Need to build a task that retains an old run of pipeline, using the buildid of the old run

Swathi 1 Reputation point

I have looked at this article :
It shows how to retain a run using a task. I was able to pin my current pipeline run using the methods suggested in the post.

I want to retain an old run of a different pipeline from my current pipeline. I have access to the buildId of the run I want to retain.

  • task: PowerShell@2
    condition: and(succeeded(), not(canceled()))
    name: RetainDMXUFSRunFromBuildId
    displayName: Retain DMX-UFS run from BuildId
    # failOnStderr: true
    targetType: 'inline'
    script: |
    $contentType = "application/json";
    $headers = @{ Authorization = 'Bearer $(System.AccessToken)' };
    $rawRequest = @{ daysValid = 365 * 2; definitionId = 1; ownerId = 'User:$(Build.RequestedForId)'; protectPipeline = $false; runId = ${<!-- -->{ parameters.rtl_build_id }} };
    $request = ConvertTo-Json @($rawRequest);
    $uri = "$(System.CollectionUri)$(System.TeamProject)/_apis/build/retention/leases?api-version=6.0-preview.1";
    Write-Output Invoke-RestMethod -uri $uri -method POST -Headers $headers -ContentType $contentType -Body $request;

When I run this pipeline, it always retains this run from the current pipeline and NOT the run for which the buildId was mentioned.

Please help me out.

Not Monitored
Not Monitored
Tag not monitored by Microsoft.
27,158 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Dave Patrick 353.7K Reputation points MVP

    The product group for Azure DevOps / TFS actively monitors questions over at

    --please don't forget to upvote and Accept as answer if the reply is helpful--

    2 people found this answer helpful.
    0 comments No comments