Using environment as variables in your Azure DevOps pipelines

When working with multiple environments in Azure DevOps pipelines, one of the approaches is to have a parameter file for each environment. The code itself will be the same, and we tweak the ending result by changing the parameters file that matches the environment. In the image depicted below, we have our security.json, which is the ARM template with the code, and we have the parameters file named security.prod.json, where the prod string is the one that defines the environment.

Azure DevOps pipelines

When creating your Azure DevOps pipelines, if we label our stages correctly with the environment name, we can leverage it when defining the template parameters section. When we copy and paste stages, it will always work, as long as we change the stage name to match the string on our parameter files.

To reference the stage name, use $(Release.EnvironmentName).

Azure DevOps pipelines

2 thoughts on “Using environment as variables in your Azure DevOps pipelines”

  1. Anderson Patricio

    Hi Sandeep,
    ARM Templates have a variable section where you create your variables dynamically.

    You may want to use parameters in ARM Templates, and those you can address from the Azure DevOps pipeline. We showed how that works in a couple of articles here at Techgenix that I wrote in the recent past.

    Let me know if you can’t find those.

Leave a Comment

Your email address will not be published.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Scroll to Top