Checkout Additional Git Repos in Azure Pipeline

October 26, 2020

The typical use case for my department is that when a build is triggered in Azure DevOps, we automatically load the single Git repository.

Note that for these examples, the self repository is named ProductXYZ. the self repo is the one that triggered the build to occur because of an automatic trigger (someone committed changes to the repo) or the build was triggered manually.

When a build is triggered, the typical YAML script will load the self repo is two simple lines.

resources:
- repo: self

To add additional Git repositories, it now becomes a two step approach. First identify the additional repos. Note that the self repo (the one that triggered the build) does not need to be specified here.

The second step is to load all the repos – including the self repo.

resources:
  repositories:
  - repository: BuildTools    # Label to use in "checkout" steps.
    type: git
    name: BuildTools          # Repository name

steps:
- checkout: self              # Get triggering repository (ProductXYZ)
- checkout: BuildTools        # Get second repo

The new folder structure in the build environment will be as follows. Note that there are many aliases for the source folder. All of them point to a physical address of something like C:\agent_work\8\s.

$(BUILD.REPOSITORY.LOCALPATH)
$(BUILD.SOURCESDIRECTORY)
$(SYSTEM.DEFAULTWORKINGDIRECTORY)
    ┃
    ┣━ BuildTools/
    ┃    ┗━ repository contents...
    ┃     
    ┣━ ProductXYZ/  
    ┃    ┗━ repository contents...
    ┃

Links