Advanced Setup: Deploy to multiple targets
In this example, you will learn how to target deployments to more than one environment.
The sample will enable you to work on two different branches, where each branch will deploy to a different environment.
Replace the azure-release-pipeline.yaml
with the one called azure-release-pipeline-more-targets.yaml
. It's okay to rename azure-release-pipeline-more-targets.yaml
.
Its locations in the sample scripts are:
Bash:
/V2/bash/azuredevops/advanced
PowerShell:
/V2/powershell/azuredevops/advanced
Make sure you don't have multiple YAML files that contain triggers (unless you designed your pipeline's workflow that way).
Now you need the aliases of the environments you want to target.
Insert the aliases into the placeholders in azure-release-pipeline-more-targets.yaml
, the values you need to replace are:
##Your target environment alias here##
##Your other target environment alias here##
Remember to fix the projectId placeholder if you haven't already: ##Your project ID here##
Next, look at the triggers for the pipeline:
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 statement if [ "$(Build.SourceBranchName)" = "main" ]; then
or elif [ "$(Build.SourceBranchName)" = "flexible" ]; then
.
The code will write which alias is targeted and write a pipeline variable (targetEnvironment
). This variable is then used by later steps.
When updating the triggering branch names, it must be updated in the two mentioned places: In the trigger and in the script.
Last updated
Was this helpful?