I want to know which pipeline triggered my YAML release pipeline.
Below is a sample YAML file of the release pipeline:
resources:
pipelines:
- pipeline: Dev_Pipeline_Source_BuildPipeline
source: Dev-Pipeline
trigger: true
- pipeline: Main_Pipeline_Source_BuildPipeline
source: Main-Pipeline
trigger: true
trigger: none
variables:
- name: CTriggeringAlias
value: $[variables['Resources.TriggeringAlias']]
- name: CRunName
value: $( resources.pipeline.$(CTriggeringAlias).runName )
CTriggeringAlias
is correctly evaluated to Dev_Pipeline_Source_BuildPipeline
. However, I also want to get the runName of the triggering resource pipeline.
CRunName
doesn't seem to work.
Is there any predefined YAML way to find the runName of the triggering build when multiple pipeline resources with triggers enabled are defined?
You can set the variable $(CRunName)
in scripts based on the CTriggeringAlias
value.
Sample YAML:
resources:
pipelines:
- pipeline: Dev_Pipeline_Source_BuildPipeline
source: Dev-Pipeline
trigger: true
- pipeline: Main_Pipeline_Source_BuildPipeline
source: Main-Pipeline
trigger: true
trigger: none
variables:
- name: CTriggeringAlias
value: $(Resources.TriggeringAlias)
steps:
- script: |
if [ "$(CTriggeringAlias)" == "Dev_Pipeline_Source_BuildPipeline" ]; then
echo "##vso[task.setvariable variable=CRunName]$(resources.pipeline.Dev_Pipeline_Source_BuildPipeline.runName)"
elif [ "$(CTriggeringAlias)" == "Main_Pipeline_Source_BuildPipeline" ]; then
echo "##vso[task.setvariable variable=CRunName]$(resources.pipeline.Main_Pipeline_Source_BuildPipeline.runName)"
fi
displayName: 'Set CRunName variable'
- script: |
echo "The CTriggeringAlias is $(CTriggeringAlias) "
echo "The triggering pipeline run name is $(CRunName)"
displayName: 'Display RunName'
Test result: