0
votes

I'm trying to use 1 ARM template for all deployments, so I'm thinking I can use an Azure DevOps pipeline variable to do some string replacement for resource names, like so.

myapi-dev-appserviceplan myapi-prod-appserviceplan

Where 'dev' and 'prod' are variables in the release pipeline, but I am unsure how to reference these in the ARM template?

2

2 Answers

0
votes

You can use token replace task (if you pick this you need to define token in file and then define variables in you pipeline which will be used to replace those tokens. You can define variables gorups to hold variables per envrionment and switinch between variables for releases) but for your case I recommend to use parameters files per envrionment. In taht way you will be just changing file for environment on deployment.

Taken from docs:

To deploy to different environments, create more than one parameter file. When naming the parameter file, add a way to identify its use. For example, use azuredeploy.parameters-dev.json and azuredeploy.parameters-prod.json

Then you can use AzureResourceGroupDeployment@2 to select proper parameter file (in case below it is WebSite.parameters.json)

- task: AzureResourceGroupDeployment@2
  displayName: 'Deploy template'
  inputs:
    deploymentScope: 'Resource Group'
    ConnectedServiceName: 'demo-deploy-sp'
    subscriptionName: '01234567-89AB-CDEF-0123-4567890ABCDEF'
    action: 'Create Or Update Resource Group'
    resourceGroupName: 'demogroup'
    location: 'Central US'
    templateLocation: 'URL of the file'
    csmFileLink: '$(artifactsLocation)WebSite.json$(artifactsLocationSasToken)'
    csmParametersFileLink: '$(artifactsLocation)WebSite.parameters.json$(artifactsLocationSasToken)'
    overrideParameters: '-_artifactsLocation $(artifactsLocation) -_artifactsLocationSasToken "$(artifactsLocationSasToken)"'
    deploymentMode: 'Incremental'
0
votes

Just throwing out an alternative to use YAML Pipelines vs the Classic Build and Release Pipelines.

This would allow you to build and deploy in the same pipeline and can read variables from the pipeline by defining them either in a variable group, variable YAML file, or a variable the specific pipeline run(https://docs.microsoft.com/en-us/azure/devops/pipelines/process/variables?view=azure-devops&tabs=yaml%2Cbatch)