5
votes

Is it possible to have a yaml pipeline trigger on commits/PRs for branches of different repositories (e.g. Repo A) to the one the azure-pipelines.yaml file is in (e.g. Repo B)?

I'm aware I can build the pipeline against Repo B and have it checkout Repo A using e.g:

resources:
  repositories:
  - repository: Repo A
    type: github
    endpoint: ***
    name: ***/RepoA

trigger:
 - master

But the trigger is only applying to Repo B, i.e. when I make a commit on master to Repo A, the pipeline does not trigger.

2

2 Answers

4
votes

The "Sprint 173" release seems to be including the multi-repo triggers feature. I suspect you might be missing the ref.

Here is an example that shows how to define multiple repository resources in a pipeline and how to configure triggers on all of them.

trigger:
- main

resources:
  repositories:
  - repository: tools
    type: git
    name: MyProject/tools
    ref: main
    trigger:
      branches:
        include:
        - main
        - release

The pipeline in this example will be triggered if there are any updates to:

  • main branch in the self repo containing the YAML file
  • main or release branches in tools repo
1
votes

Unfortunately Multi-repo triggers is supported for Github repo resources yet.

As it is said in the document:

Repository resource triggers only work for Azure Repos Git repositories at present. They do not work for GitHub or Bitbucket repository resources.

If you were using Azure Repos Git repositories. You need to specify the trigger section for the repository resources in order to enable the Multi-repo triggers. See document here for more information.

Since you are using github, you can use pipeline completion triggers as workaround. You can refer to below steps to setup a pipeline completion trigger for RepoB pipeline.

1, Set up the triggering pipeline for RepoA.

You can create a pipeline for github RepoA in azure devops. Classic UI pipeline is recommanded, for it won't add a azure-pipelines.yaml file in your RepoA.

I suggest you add a empty agent job(without any tasks)in the triggering pipeline. So that the pipeline run will always be successful.

enter image description here

You need to Enable continuous integration for this triggering pipeline. So that the commits/PRs for branches in RepoA will automatically trigger this pipeline.

In the pipeline Edit page, Go to Triggers tab, Check Enable continuous integration, Add the branches you want to enable CI in the Branches Filters section

enter image description here

2, Set up pipeline resources in triggered pipeline (ie. azure-pipelines.yaml file for RepoB)

Add the pipeline resources and specify the trigger section in the pipeline resource. See below example:

resources:
  repositories:
  - repository: Repo A 
    type: github
    endpoint: ***
    name: ***/RepoA

  pipelines:
  - pipeline: repoAPipeline   # Name of the pipeline resource
    source: triggeringPipeline-RepoA # Name of the triggering pipeline
    trigger: 
      branches:
      - releases/*
      - master

When changes are made to RepoA, the triggering pipeline will be triggered and complete successfully. When the triggering pipeline is completed, Pipeline for RepoB will be triggered.

By setting up the triggering pipeline for RepoA and the pipeline resources in pipeline of RepoB. You can achieve the same effect with Multi-repo triggers.