Pass Variables to ARM Templates Using Azure DevOps Pipeline

This Azure DevOps Pipelines blog post will show you how to pass variables to an ARM template.

Azure DevOps Pipelines

Azure DevOps pipelines allow us to create CI/CD deployments driven by source code changes or manually triggering them. The pipelines are based on YAML and can be managed using source control.

Variables

In our use case, we have an ARM deployment of a MySQL server. The deployment needs a password, and we have decided to use variables that we can pass the deployment.

Below is the variable that we will target. It is the MySQL server password.

     },
        "administratorLoginPassword": {
            "value": null
        },

To create a variable in our template, we use the Variables button located in the pipeline editor.

In the variable screen, we define the variable and save it.

YAML

The configuration in the YAML file looks like this.

overrideParameters: '-administratorLoginPassword $(VAR_MYSQL_PASS)'

To access the variable, we use the following syntax.

$(VAR_MYSQL_PASS)

If you look at the parameters configuration, I’m allowing overriding the values of the parameters.

Below is the YAML code for the ARM templates with the variable.

- task: AzureResourceManagerTemplateDeployment@3
  inputs:
    deploymentScope: 'Resource Group'
    azureResourceManagerConnection: 'details'
    subscriptionId: 'your sub id'
    action: 'Create Or Update Resource Group'
    resourceGroupName: 'Linux-Web-Hosting'
    location: 'west-us'
    templateLocation: 'Linked artifact'
    csmFile: 'mysql/template.json'
    csmParametersFile: 'mysql/parameters.json'
    overrideParameters: '-administratorLoginPassword $(VAR_MYSQL_PASS)'
    deploymentMode: 'Incremental'

Processing…
Success! You're on the list.

Posted

in

,

by

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.