Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running a YAML build pipeline manually with artifacts selected from resources in the UI are ignored

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)
like image 688
tjeerdnet Avatar asked Oct 15 '25 14:10

tjeerdnet


1 Answers

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.

like image 56
Krzysztof Madej Avatar answered Oct 18 '25 03:10

Krzysztof Madej



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!