I have a question about deploying to different environments (Test / Production) with one pipeline.
In this scenario I have a test and production environment. With the same configuration for deploying web application to Azure for two countries. In the current situation we have a release pipeline in the production and test with two stages. One stage for country A and one stage for country B.
What I did is as follows:
variables.yml
file.What I want to do is:
The same goes for the production and test environment. depending on the environment, I want to be able to point to the correct YAML variables.yml.
How can I achieve this?
Unclear what obstructed your design pipeline, however, based on your current requirements, the YAML pipeline structure was straightforward. Since you have two variables template .yml
files, you can import diffrent templates in respective deployment jobs and each deployment can be configured to run against its corresponding environment.
# Your used to deploy web apps via release pipeline, so assumed there was already a pipeline resource that generated build artifacts. To use that build artifact from the pipeline resource below:
resources:
pipelines:
- pipeline: BuildWebApp
project: TheProjectName
source: ThePipelineName
stages:
- stage: Deploy
displayName: Deploy to Azure Web Apps
jobs:
- deployment: DeploymentJobA
displayName: Deploy to Production - Country A
variables:
- template: variablesA.yml
environment: Prod
strategy:
runOnce:
deploy:
steps:
- download: BuildWebApp
displayName: Download artifacts for deployment from the pipeline resource
- script: |
echo "ARM Service Connetion for deployment is $(ARMSvcCnnName)"
echo "Azure Web App name is $(AzureWebAppName)"
displayName: Check the variable values in variables.yml
- task: AzureRmWebAppDeployment@4
inputs:
ConnectionType: 'AzureRM'
azureSubscription: '$(ARMSvcCnnName)'
appType: 'webApp'
WebAppName: '$(AzureWebAppName)'
packageForLinux: '$(System.DefaultWorkingDirectory)/**/*.zip'
- deployment: DeploymentJobB
displayName: Deploy to Test - Country B
variables:
- template: variablesB.yml
environment: Test
strategy:
runOnce:
deploy:
steps:
- download: BuildWebApp
displayName: Download artifacts for deployment from the pipeline resource
- script: |
echo "ARM Service Connetion for deployment is $(ARMSvcCnnName)"
echo "Azure Web App name is $(AzureWebAppName)"
displayName: Check the variable values in variables.yml
- task: AzureRmWebAppDeployment@4
inputs:
ConnectionType: 'AzureRM'
azureSubscription: '$(ARMSvcCnnName)'
appType: 'webApp'
WebAppName: '$(AzureWebAppName)'
packageForLinux: '$(System.DefaultWorkingDirectory)/**/*.zip'
Even though the variable names in each template are the same, since the two templates variablesA.yml
and variablesB.yml
work for respective deployment job scope, the variable values are different during runtime.