Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AzureDevOps - DownloadPipelineArtifact@2 does not download artifact if the very previous run didnt produce artifact

We are using Azure Pipelines (YAML not classic) for both build & releases. The stages are as follows:

  1. Build
  2. Deploy_DEV
  3. Deploy_UAT
  4. Deploy_PERF
  5. Deploy_PROD

The YAML is parameterised that user can select what stages to run. For example:

  1. Build & Deploy DEV, or
  2. Build + Deploy DEV + Deploy UAT.

Now problem arises in scenarios like below:

  1. Build + Deploy DEV. >> Outcome: Works
  2. Deploy SIT (DownloadPipelineArtifact@2 with runVersion: 'latestFromBranch') >> Outcome: works because last build Id produced artifact and deployment was successful
  3. Deploy UAT (DownloadPipelineArtifact@2 with runVersion: 'latestFromBranch') >> Outcome fails, because the very last deploy job to SIT didnt produce any artifact.

I dont know if its a bug or shortcoming of this pipeline task, but would expect the DownloadPipelineArtifact@2 tasks refer to the very last build Id of the branch that produced the artifact. It seem from the logs that DownloadPipelineArtifact@2 task simply tries to download artifact from very previous pipeline run which may not have produced any artifact.

Its very normal during any project to run 1 build & and then deploy that build over time to various environment (promoting artifact). So pipeline stages per run would look like:

  1. Build artifact 1 on a commit
  2. Deploy artifact 1 to Env x
  3. Deploy artifact 2 to Env y
  4. Deploy artifact 3 to Env z ... etc.

Can someone advise if this is a shortcoming of the task or am I doing something wrong?

Below is my task configuration:

- task: DownloadPipelineArtifact@2
  displayName: Download LATEST artifact
  inputs:
    buildType: 'specific'
    project: '$(System.TeamProjectId)'
    definition: '$(System.DefinitionId)'
    runVersion: 'latestFromBranch'
    branchName: '$(Build.SourceBranch)'
    targetPath: '$(Pipeline.Workspace)'

like image 673
RogerIsDead Avatar asked Dec 31 '25 11:12

RogerIsDead


1 Answers

"DownloadPipelineArtifact" task with 'specific' buildType checks the last successful build in the pipeline, if there is no artifact produced in the last successful build, you would get "Artifact art was not found for build xxx". This is how "DownloadPipelineArtifact" task works.

To solve your issue, there are two ways:

  1. For every pipeline run, you run two stages (Build + Deployment), then set 'current' buildType for "DownloadPipelineArtifact" task. In this way, you could always get the latest artifact, and I recommend this way.

  2. Add "PublishPipelineArtifact" task in each Deployment stage, so that there always have artifact in the pipeline run.

       - task: DownloadPipelineArtifact@2
         inputs:
           buildType: 'specific'
           project: '94eb5b0e-78fd-4ec0-a3c5-62d5becb6c0f'
           definition: '119'
           buildVersionToDownload: 'latest'
           artifactName: 'A.A'
           targetPath: '$(Pipeline.Workspace)'
       - task: PublishPipelineArtifact@1
         inputs:
           targetPath: '$(Pipeline.Workspace)/A.A'
           artifact: 'A.A'
           publishLocation: 'pipeline'
    
like image 188
Cece Dong - MSFT Avatar answered Jan 04 '26 23:01

Cece Dong - MSFT



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!