I am setting up a build job that needs to be triggered by another build pipeline.
trigger:
- main
resources:
pipelines:
- pipeline: triggeredpipeline # Name of the pipeline resource.
source: <pipeline path and name> # The name of the pipeline referenced by this pipeline resource.
project: <ADO project name> # Required only if the source pipeline is in another project
trigger: true # Run app-ci pipeline when any run of security-lib-ci completes
pool: Default
Next step is to get artifacts from the triggering job to do the magic in the triggered build job.
Now I run into the situation that ADO 'download' (https://learn.microsoft.com/en-us/azure/devops/pipelines/yaml-schema/steps-download?view=azure-pipelines) allows me to reuse the pipeline reference, but does not allow me to explicitly specify the target location.
- download: triggeredpipeline # pipeline resource identifier.
displayName: Download files from triggering pipeline
artifact: Platform
It will, like stated in the documentation, write it to $(Pipeline.Workspace)/<pipeline resource identifier>/<artifact name>
, e.g. /triggeredpipeline/Platform (or content in Platform)
Now the documentation states that download
is a shorthand for DownloadPipelineArtifact@2, and according to that documentation (https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/reference/download-pipeline-artifact-v2?view=azure-pipelines) it is possible to specify a targetPath
. What I do not see / understand how I can reuse my pipeline reference. I can only set the ids of the project and pipeline triggering my build.
- task: DownloadPipelineArtifact@2
inputs:
buildType: 'specific'
project: '<uuid>'
definition: '266'
buildVersionToDownload: 'latest'
artifactName: 'Platform'
targetPath: '$(Build.ArtifactStagingDirectory)'
So how can I use my reference to my trigger ( pipeline: triggeredpipeline
) but still being able to define what the target folder is.
(and yes, I could add some task that does the copy, but the size of the source artifact is considerable so downloading, then again moving / copying it is a waste of time)
I hope one of you have worked with triggered build pipelines before and know a way to reuse the trigger reference to download the artifact(s) to the right spot in 1 go.
You can use metadata listed 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
And combine them with DownloadPipelineArtifact@2
- task: DownloadPipelineArtifact@2
inputs:
buildType: 'specific'
project: '$(resources.pipeline.triggeredpipeline.projectID)'
definition: '$(resources.pipeline.triggeredpipeline.pipelineID)'
specificBuildWithTriggering: true
buildVersionToDownload: 'specific'
pipelineId: '$(resources.pipeline.triggeredpipeline.runID)'
artifactName: 'Platform'
targetPath: '$(Build.ArtifactStagingDirectory)'