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

Swathi 1 Reputation point
2021-09-10T21:05:05.24+00:00

I have looked at this article : https://learn.microsoft.com/en-us/azure/devops/pipelines/policies/retention?view=azure-devops&tabs=yaml
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.
snippet:

  • task: PowerShell@2
    condition: and(succeeded(), not(canceled()))
    name: RetainDMXUFSRunFromBuildId
    displayName: Retain DMX-UFS run from BuildId
    inputs:
    # 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.

Community Center | Not monitored
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Anonymous
    2021-09-10T21:08:35.503+00:00

    The product group for Azure DevOps / TFS actively monitors questions over at
    https://developercommunity.visualstudio.com/report?space=21&entry=problem
    https://developercommunity.visualstudio.com/report?space=22&entry=problem

    --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

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.