How to reference a Feature Branch Inside an Azure DevOps Pipeline

When working with Azure Pipelines, you may need to access a repository and reference its code from a specific feature branch instead of the default branch. I am dealing with this scenario almost everyday and the most common case is testing changes made on a feature branch, before they’re merged to the main branch.

The ref property to the rescue

Use the ref property in your repository resources definition like in the following example:

resources:
    repositories:
    - repository: <name-of-the-external-repository>
      type: git
      name: <project-name>/<repository-name>
      ref: refs/heads/<feature-branch-name>

We have the following key components:

You can then use the referenced repository by name with the help of the @ notation, for example:

steps:
- template: templates/build/standard.yml@<name-of-the-external-repository>
comments powered by Disqus