Search code examples
azure-devopsazure-pipelinesazure-pipelines-yamlazure-pipelines-tasks

Downloading latest Pipeline Artifact from branch based on Tag


I am trying to download the latest available artifact for a given tag from the current build pipeline and branch, but I am getting the following error.

##[error]No builds currently exist in the pipeline definition supplied.

This is a 3 stage pipeline for automation testing with build, deploy, and run tests stages. In the run tests stage I am trying to download the most recently available artifact in the build stage, which might be this run, or it might be an earlier run.

If I leave the tags option out, it will try and fetch it from the last available run, but this artifact may not have been created then, hence my use of tags to try and filter it.

    - task: DownloadPipelineArtifact@2
      displayName: 'Download Latest DLLs'
      inputs:
        source: 'specific'
        project: $(System.TeamProjectId)
        pipeline: $(System.DefinitionId)            
        runVersion: 'latestFromBranch'
        runBranch: $(Build.SourceBranch)
        tags: 'myBuildTag'
        allowPartiallySucceededBuilds: true
        artifact: myArtifactName            
        patterns: '**/IntegrationTests/**/*'                      
        path: '$(Agent.TempDirectory)\myArtifactName'
      continueOnError: true

Any help would be appreciated


Solution

  • Downloading latest Pipeline Artifact from branch based on Tag

    I could reproduce this issue on my side.

    I assume this is an issue for the DownloadPipelineArtifact task in the multiple stages with tags.

    After much investigation, I found if we use the DownloadPipelineArtifact task in the multi stages:

    - task: DownloadPipelineArtifact@2
      displayName: 'Download Latest DLLs'
      inputs:
        source: 'specific'
        project: $(System.TeamProjectId)
        pipeline: $(System.DefinitionId)            
        runVersion: 'latestFromBranch'
        runBranch: $(Build.SourceBranch)
    

    it will try to download the latest build on specify branch. Since we use the multi stages, the build stage is successfully in current pipeline, this task DownloadPipelineArtifact will download the artifact from previous build stage. However, the tag has not been added at this time, it needs to be added after the pipeline is completed:

    enter image description here

    In this case, we will receive that error No builds currently exist in the pipeline definition supplied..

    Because the current pipeline where the build stage generates the artifact has not been tagged with tags, its tag is empty.

    The key to this issue is that the multi-stage yaml makes the build and test in the same pipeline. It is different from the classic pipeline. We are not using the task DownloadPipelineArtifact after a pipeline is completed.

    I submit this issue on azure devops task: https://github.com/microsoft/azure-pipelines-tasks/issues/13101. You could check this ticket for feedback.

    Hope this helps.