2
votes

We have a YAML file (pipelineB) which does what it must do, it downloads the latest build artifact from a specific other existing build pipeline (pipelineA). This is automatically triggered. Now we want to run this build pipelineB manually and be able to select another artifact version to be used. In the Azure DevOps build pipeline there is an option saying "Run pipeline" where you can select "Resources" to be used. If you select a resource you end up with a list of all builds from pipelineA which you can choose from.

Run pipeline

Resources

PipelineA runs

If we then choose an older (e.g. 1.2.43-10019-master) build from the pipeline runs of pipelineA and run pipelineB and we look in the logging we see that it ignores what we manually selected and always downloads the latest version. I can understand that it does that because the DownloadBuildArtifact@0 step tells to use the latestFromBranch build version to download.

My question: how can we make use of manually selecting a resource build artifact and use the selected version further in the YAML pipeline? And ideally by default if you don't do a manual run/selection it should just use the latest version of an artifact.

Below an exerpt from our YAML pipeline:

name: pipelineB

resources:
  pipelines:

  - pipeline: pipelineA
    source: pipelineA
    branch: master
    trigger:
      branches:
        - master

steps:

  - task: DownloadBuildArtifacts@0
    name: 
    displayName: 'Download pipelineA artifact'
    inputs:
      buildtype: specific
      project: ourProjectName
      pipeline: pipelineA
      branchName: refs/heads/master
      buildVersionToDownload: latestFromBranch
      downloadType: specific
      downloadPath: $(Pipeline.Workspace)

Working solution based on answer by @Krzysztof Madej. Only for the step DownloadBuildArtifacts@0 the field buildVersionToDownload needs to be changed to specific and a new field needs to be introduced buildId referring to the pipelineA resource.

steps:

  - task: DownloadBuildArtifacts@0
    name: 
    displayName: 'Download pipelineA artifact'
    inputs:
      buildtype: specific
      project: ourProjectName
      pipeline: pipelineA
      branchName: refs/heads/master
      buildVersionToDownload: 'specific'
      downloadType: specific
      buildId: '$(resources.pipeline.pipelineA.runID)'
      downloadPath: $(Pipeline.Workspace)
1
Hi @tjeerdnet, Just checking in to see whether this issue is still blocking you now? Any update for this issue? If the answer could help, you may consider accepting it.Vito Liu
@VitoLiu-MSFT I today had the opportunity to test it and updated my question with the answer. It works as expected now :) - although I find it hard to find this in the Azure DevOps pipeline documentation that if you do a manual build and select a different resource that it overrides the download task runIDtjeerdnet

1 Answers

3
votes

Please change buildVersionToDownload to specific and then use buildId: '$(resources.pipeline.hadar.runID)'

  - task: DownloadBuildArtifacts@0
    inputs:
      buildType: 'specific'
      project: '4fa6b279-3db9-4cb0-aab8-e06c2ad550b2'
      pipeline: '72'
      branchName: 'refs/heads/master'
      buildVersionToDownload: 'specific'
      downloadType: 'single'
      downloadPath: '$(Pipeline.Workspace)'
      artifactName: 'drop'
      buildId: '$(resources.pipeline.hadar.runID)'

You can check available variables for pipeline resource here

resources.pipeline.<Alias>.projectName
resources.pipeline.<Alias>.projectID
resources.pipeline.<Alias>.pipelineName
resources.pipeline.<Alias>.pipelineID
resources.pipeline.<Alias>.runName
resources.pipeline.<Alias>.runID
resources.pipeline.<Alias>.runURI
resources.pipeline.<Alias>.sourceBranch
resources.pipeline.<Alias>.sourceCommit
resources.pipeline.<Alias>.sourceProvider
resources.pipeline.<Alias>.requestedFor
resources.pipeline.<Alias>.requestedForID

I checked it again and simple

  - download: pipelineA

works as code above.