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.