Tuesday, October 27, 2020

Trigger an Azure Build Pipeline Based on Changes in Multiple Azure Git Repos

While we are working in the projects, there can be common tools or utilities developed which are shared with the multiple projects. When developing such projects using Azure DevOps Repos as source control, we can keep common utilities in one repo and other projects in separate repos. However, while we developing utilities in separate repo, once any change done to the utilities, other projects which refer this utility should be get acknowledge and should be able to work with the latest utilities. Hence, once new change done to the utilities code, other dependent projects builds should get triggered automatically and build deployable package with latest utilities version.

Azure DevOps has a feature where you can trigger a build pipeline once a change is done to another repo other than the main code repo. That would help us to achieve the above-mentioned challenge. This post discusses how to trigger a build pipeline due to the code push done to the multiple repos.

In this sample, we use RepoX which has utility code, RepoA has a project which use the utilities for the project development. We have created the build pipeline, Repo A as main repo and Repo X as external repo. Further, the build will get triggered once any change is done to Master branch of RepoA or RepoX.

Following is the Sample code of YAML build pipeline in DemoWebbApp project.

trigger:
  - master

resources:
  repositories:
    - repository: RepoX
      type: git
      name: DemoWebbApp/RepoX
      ref: master
      trigger:
        branches:
          include:
            - master

Let’s try to understand each important part of the YAML file as follows.

trigger:
  - master

  • Once any change is push to master branch of the RepoA, build triggers.

  repositories:
    - repository: RepoX
      type: git
      name: DemoWebbApp/RepoX
      ref: master
      trigger:
        branches:
          include:
            - master

  • This part explains how to set build triggers for another Repo. According to the above YAML code segment, once a change is done to the master branch of the RepoX, build pipeline will get triggered.

Likewise, we can set multiple triggers from multiple repos. Once any change done to the master branch of RepoX or RepoA build get triggered. To get more idea of the build pipeline, go to triggered build pipeline and you would be able to see multiple sources as mention in following image.



To see more details of the changes in the build in the pipeline, click on "view changes" button on the build summary page. It will open the page which display all the changes built in the selected build.

As you can see in the above image, build has changes done in both RepoA and RepoX. That means once you have made any change to RepoA or RepoX, build will get triggered. This feature is useful when there are common scripts, frame works or utilities shared in multiple repos.


No comments:

Post a Comment