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:
repository
: Alias to reference this repo elsewhere in your pipelinetype
: Repository type (git, github, bitbucket)name
: Full repository identifier in format Project/Repositoryref
: Reference to a specific branch. If you have a feature branch which is inside a folder likefix
orfeature
, then you will have to use the followingref: refs/heads/fix/<feature-branch-name>
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>