In Azure DevOps, I set up a pipeline No.1 that has pipeline No.2 resource defined with a trigger. According to the documentation here https://learn.microsoft.com/en-us/azure/devops/pipelines/process/resources?view=azure-devops#pipelines-resource-definition the No.1 pipeline should trigger when No.2 pipeline has produced an artifact.
But that doesn't happen - instead, No.1 pipeline is triggered when No.2 pipeline starts, with a reference to the previous run on the No.2 pipeline and artifact of the previous run.
My setup:
pool:
vmImage: ubuntu-latest
resources:
pipelines:
- pipeline: No2Pipeline # Alias for the upstream pipeline
source: CI Pipeline
trigger:
branches:
- dev
steps:
- download: No2Pipeline
artifact: dummy # <-- here is the artifact of the previous run
- script: |
echo $(resources.pipeline.No2Pipeline.runID) # <-- here is the id of previous run
How can I change the setup to trigger No.1 pipeline when No.2 pipeline completes? Or at least with a reference to current run of No.2 pipeline?
YAML pipelines are configured by default with a CI trigger on all branches. This means if you do not explicitly set the CI trigger using the trigger
key in the pipeline YAML file, any changes pushed to a branch will trigger the pipeline as long the YAML file is existing on the latest commit of that branch.
For your case, since the YAML file of the No.1 pipeline is existing on the dev
branch and also does not have CI trigger set explicitly, when you push changes to dev
branch, the No.1 pipeline also will be triggered by the new push. That's why you see the trigger type of the run for No.1 pipeline is IndividualCI
.
If you want the No.1 pipeline can only be triggered by the No.2 pipeline for dev
branch, you can configure the YAML file of No.1 pipeline like as below:
Disable CI trigger by set "trigger: none
" in the YAML file.
. . .
# Disable CI trigger.
trigger: none
resources:
pipelines:
- pipeline: No2Pipeline # Alias for the upstream pipeline
source: CI Pipeline
trigger:
branches:
- dev
. . .
Ensure the YAML file of No.1 pipeline with above configuration is existing always on the latest commit of dev
branch.
With above configuration, when you push new changes to the dev
branch, the No.2 pipeline is triggered due to the CI trigger, the No.1 pipeline is not triggered. After the run of No.2 pipeline is completed successfully, the No.1 pipeline is triggered.