Deploy from multiple branches using Azure Pipelines

Azure DevOps Services | Azure DevOps Server 2022 - Azure DevOps Server 2019

Artifact filters can be used with release triggers to deploy from multiple branches. Applying the artifact filter to a specific branch enables deployment to a specific stage when all the conditions are met.

Prerequisites

  • A Git repository to create the pipeline. If you don't have one, use the pipelines-dotnet-core sample app.

  • A working build for your repository.

Set up a release pipeline

  1. Select Releases under Pipelines. If this is your first release pipeline, select New Pipeline, otherwise select Create a release.

  2. Select Start with an empty job when prompted to select a template.

  3. Select Add an artifact and specify the project, the build pipeline, and the default version. Select Add when you are done.

    Add build artifact to release pipeline

  4. Select the Continuous deployment trigger icon and enable the Continuous deployment trigger to create a release every time a new build is available.

    Enable continuous deployment trigger

  5. Under Stages, select the stage and rename it to Dev. This stage will be triggered when a build artifact is published from the dev branch.

    Configure Dev stage

  6. Select the Pre-deployment conditions icon in the Dev stage and set the deployment trigger to After release to trigger a deployment to this stage every time a new release is created.

    Set pre-deployment trigger to after release

  7. Enable the Artifact filters. Select Add and specify your artifact and build branch.

    Enable Artifact filters

  8. Under Stage, select Add then New stage to add a new stage. Select Start with an empty job when prompted to select a template, and rename the stage to Prod. This stage will be triggered when a build artifact is published from the main branch. Repeat the steps 6-8 and replace the Build branch for this stage to main.

    Set up Prod with the main branch

  9. Add to each stage all the relevant deployment tasks to your environment.

Now the next time you have a successful build, the pipeline will detect which branch triggered that build and trigger deployment to the appropriate stage only.

Deployment status