Introduction:
Pipelines frequently require multiple repositories containing source code, tools, scripts, or other necessary components for building your code. Utilizing multiple checkout steps within your pipeline enables you to retrieve and incorporate these additional repositories alongside the one housing your YAML pipeline.
In this article, we will see how to stage the different environments in the pipeline using multiple repositories triggers.
When do you need this?
When you’re using a tool or library from another repository, and you want to run tests for your application whenever that tool or library is updated.
If the YAML file is stored in a different repository than your application code, you aim to activate the pipeline each time there’s a new update pushed to the application repository. To avoid the developer interaction with the pipeline
My Case:
I have a standalone pipeline repository called “multi-trigger-pipeline” with an “azure-pipeline. yaml” file, which will be triggered based on the commit that happened in different branches in other repositories in my case the repository is “AzureB2C”.
Created a pipeline using azure-pipeline.yaml from the repo multi-trigger-pipeline.
Multi Trigger Pipeline
If your repository needs a service connection or extra resource details, make sure to use a repository resource. Some repository types need a service connection.
resources:
repositories:
- repository: AzureB2C
type: git
name: Azure Launch/AzureB2C
trigger:
branches:
include:
- dev
- stagingThe repository resource in the above code is used to define the repository and repository. The trigger is included for the dev and staging branches, so whenever the code is committed in any one of the branches, it triggers the pipeline and executes the respective stages in the pipeline.
variables:
isStaging: $[eq(variables['Build.SourceBranch'], 'refs/heads/staging')]
isDev: $[eq(variables['Build.SourceBranch'], 'refs/heads/dev')]
resources:
repositories:
- repository: AzureB2C
type: git
name: Azure Launch/AzureB2C
trigger:
branches:
include:
- dev
- staging
- repository: coreAPIDemo
type: git
name: Azure Launch/coreAPIDemo
trigger:
branches:
include:
- dev
- staging
stages:
- stage: TestStatus
jobs:
- job: Print
condition:
steps:
- script: echo staging $(isStaging)
- script: echo Dev $(isDev)
- stage: Staging
condition: and(succeeded(), eq(variables.isStaging, true))
jobs:
- job: Build
steps:
- script: echo Building for Staging
- stage: Dev
condition: eq(variables.isDev, true)
jobs:
- job: Build
steps:
- script: echo Building for Dev
We have two stages in the pipeline, it is all based on the environment. The staging and Dev stages will be triggered whenever there is a commit from the staging branch and Dev branch respectively based on the condition of each stage.
You can also extend to many repositories.
resources:
repositories:
- repository: AzureB2C
type: git
name: Azure Launch/AzureB2C
trigger:
branches:
include:
- dev
- staging
- repository: coreAPIDemo
type: git
name: Azure Launch/coreAPIDemo
trigger:
branches:
include:
- dev
- staging
Now we extended the pipeline and added one more repository to the resource.
Note: You cannot refer the repositories from other projects

Commit from the dev branch AzureB2C repo.

Commit from the dev branch CoreAPIDemo repo.
Complete code:
| trigger: | |
| branches: | |
| include: | |
| – dev | |
| – staging | |
| variables: | |
| isStaging: $[eq(variables['Build.SourceBranch'], 'refs/heads/staging')] | |
| isDev: $[eq(variables['Build.SourceBranch'], 'refs/heads/dev')] | |
| resources: | |
| repositories: | |
| – repository: AzureB2C | |
| type: git | |
| name: Azure Launch/AzureB2C | |
| trigger: | |
| branches: | |
| include: | |
| – dev | |
| – staging | |
| – repository: CoreAPIDemo | |
| type: git | |
| name: Azure Launch/CoreAPIDemo | |
| trigger: | |
| branches: | |
| include: | |
| – dev | |
| – staging | |
| stages: | |
| – stage: TestStatus | |
| jobs: | |
| – job: Print | |
| steps: | |
| – script: echo staging $(isStaging) | |
| – script: echo Dev $(isDev) | |
| – stage: Staging | |
| condition: and(succeeded(), eq(variables.isStaging, true)) | |
| jobs: | |
| – job: Build | |
| steps: | |
| – script: echo Building for Staging | |
| – stage: Dev | |
| condition: eq(variables.isDev, true) | |
| jobs: | |
| – job: Build | |
| steps: | |
| – script: echo Building for Dev | |
Summary:
We have seen how to build the Azure DevOps pipeline to handle the trigger from multiple repositories and handling the different environment in the pipeline stages using the condition.
I hope you enjoyed this article. Please share your thoughts/feedback.