Build Multiple Repositories with Single Pipeline Introduction in Azure DevOps

 This section discusses how to build multiple Repositories with a single pipeline. this could be needed when the feature you deliver may affect multiple code repositories and you need to ensure that all build together.


The resources Section on the Pipeline

To tell the pipeline about the other repositories that need to be built, you need to add the resources section before starting steps or jobs sections. let's see the resources section structure:

resources:
  repositories:
  - repository: <RepositoryAliasName>
    type: git
    name: <AzureDevOps-ProjectName>/<RepositoryName>
    ref: <BranchName>

The resources section contain sub-section repositories, which contains one or multiple repository definitions.

For each repository we need to define the following:

  • repository the value will be an alias name for the repository, this name will be used on another pipeline step checkout.
  • type: define where the repository is:
    • git: if the repository is a git repository in the same Azure DevOps server and on the same organization as the pipeline.
    • For more types check this document.
  • name: it’s a combination of the project name on Azure DevOps and the repository name.
  • ref: the branch that will check the code from.


The checkout Section in the Pipeline

After defining the values of resources.repositories, you have to check out the code, we will do that inside the steps section:

##
steps:
- checkout: <RepositoryAliasName>
##

The checkout key takes one value which is the alias name that we gave to the repository on resources.repositories.

Notes That:

  • you have to define and check even the repository that contains the pipeline.
  • The first time you run the pipeline after adding the repository and checkout, it will ask for giving permission to access the branch.

    just click View and then Permit for more information about pipeline limit job Authorization check the following link.pipeline-need-permission-first-checkout-branch


Archive the build Results

After the checkout completed, the build task can start, and the checkout step will download the source code in a folder with the same name as the repository name. Therefore, the build will be done in that folder.

You can build multiple repositories in one step if both repositories use the same framework.

After the build, you can copy or archive the build result to Artifact

- task: ArchiveFiles@2
  inputs:
    rootFolderOrFile: '<RepositoryName>/<BuildingPath>'
    includeRootFolder: false
    archiveType: 'zip'
    archiveFile: '$(Build.ArtifactStagingDirectory)/<ProjectName>.$(Build.BuildNumber).zip'
    replaceExistingArchive: true

Here we did a step for archiving one of the projects, as you notice, the Repository Name must be added as a part of the building result path.

The same can be for the copy task.

Comments

Popular posts from this blog

How to Automatically deploy Configuration Files with Azure DevOps CD pipelines

Adding Multiple DB Contexts in your DotNet Project

Adapting a New Technology: A General Guide to keep Your Systems up-to-date