Advanced Setup: Deploy to multiple targets

Learn how to set up your CI/CD pipeline to include more than one target environment.

The sample will enable you to work on two different branches, where each of the branches deploys to a different environment.

circle-info

With the CI/CD flow, you can trigger deployments to multiple environments simultaneously.

If a deployment is already in progress to a named environment, it will not be possible to trigger another until the first is done.

  1. Replace the azure-release-pipeline.yaml with the file called azure-release-pipeline-more-targets.yaml. It's okay to rename azure-release-pipeline-more-targets.yaml.

    • The file can be found in these locations within the sample files:

      • Bash: /V2/bash/azuredevops/advanced

      • PowerShell: /V2/powershell/azuredevops/advanced

  2. Ensure you don't have multiple YAML files that contain triggers (unless you designed your pipeline's workflow that way).

  3. Fetch the aliases of the environments you want to target from the Cloud portal.

  4. Insert the aliases into the following placeholders in azure-release-pipeline-more-targets.yaml:

    • ##Your target environment alias here##

    • ##Your other target environment alias here##

  5. Fill in the projectId placeholder if you haven't already: ##Your project ID here##.

  6. Look at the triggers for the pipeline:

# Trigger when committing to main or flexible branch 
trigger:
  batch: true
  branches:
    include:
      - main
      - flexible

Here, you can change when a deployment is triggered based on which branch is pushed to.

The pipeline needs to resolve the target based on the triggering branch, which is done in the following code:

The triggering branch is evaluated in the if [ "$(Build.SourceBranchName)" = "main" ]; then or elif [ "$(Build.SourceBranchName)" = "flexible" ]; then statement.

The code will write which alias is targeted and write a pipeline variable (targetEnvironment). This variable is used by steps later.

When updating the triggering branch names, it must be updated in the two mentioned places:

  • The trigger

  • The script

Last updated

Was this helpful?