There are 2 solutions for triggering a pipeline from another pipeline in Azure DevOps Pipelines using yaml syntax:
- Using 'resources' feature
- Using yaml templates
Let's explore both options.
Here is below an example of how that works. The second pipeline will be triggered after the first one finishes successfully.
# azure-pipelines.yml
name: FirstPipeline
trigger:
- main
pool:
vmImage: ubuntu-latest
steps:
- script: echo This pipeline runs first !
# azure-pipelines-trigger.yml
name: SecondPipeline
trigger: none
# this pipeline will be triggered by another pipeline
resources:
pipelines:
- pipeline: previous-pipeline-trigger # Name of the pipeline resource
source: First-Pipeline-yaml # Name of the pipeline referenced by the pipeline resource
project: Trigger-Pipeline-From-Another-Pipeline # Required only if the source pipeline is in another project
trigger: true # enable the trigger
pool:
vmImage: ubuntu-latest
steps:
- script: echo This pipeline was set to be triggered after first pipeline completes.
Note how we set the trigger for the second pipeline: 'trigger: none'. This is to trigger the pipeline when only after the first one completes (i.e not after commit or PR).
More details about resources: https://docs.microsoft.com/en-us/azure/devops/pipelines/process/resources
# azure-pipelines.yml
name: FirstPipeline
trigger:
- main
pool:
vmImage: ubuntu-latest
steps:
- script: echo This pipeline runs first and will trigger a second pipeline !
- template: 2_azure-pipelines-template.yml
# azure-pipelines-template.yml
steps:
- script: echo This pipeline will be triggered by another pipeline !
More details about templates: https://docs.microsoft.com/en-us/azure/devops/pipelines/process/templates