azure-devopsazure-pipelinesretention

Azure Devops - Does retaining a pipeline also include the artifact it is published on it?


Our default retention policy is: enter image description here

Some builds we will like to keep longer, so we added the following code:

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

And now on the pipeline we are getting this message: " This run has been retained for more than 1 year, 12 months by .. " . So the code is working.

My question is, if the pipeline published an artifact, will it also be available for the duration of the retention?

enter image description here

Or will it disappear after 30 days from the retention policy (Days to keep artifacts and attatchments). ?

Thank you.


Solution

  • if the pipeline published an artifact, will it also be available for the duration of the retention?

    Yes. The published artifact will be available for the duration of the retention.

    Refer to this doc: Set retention policies for builds, releases, and tests

    When mark a run or a release to be retained indefinitely, neither the pipeline's retention policy nor the maximum limits set by the administrator are applied when you mark an individual run or release to be retained indefinitely. It will remain until you stop retaining it indefinitely.

    In you case, when you manually set a retention date of 365*2, Pipeline run will not apply retention policy. It will retain artifacts within the set retention date.