DevOps | Scripts | Automation

Azure DevOps

How to set environment variables in Azure Pipeline?

You can set environment variables in Azure Pipeline so they can be used in the scripts and application code. This variable is process level means it is available during that pipeline run only.

To set environment variables in Azure Pipeline, the env variable is used in the steps subtasks. Below are the steps subtasks.

Let’s take some examples to understand the same.

Using the env variable at the task level

As shown in the above example, we are setting up two environment variables (var1 and var2) and they can be accessed using $env:variableName.

You can also use the same in the script as well. For example,

environmentVariable.yml

testvariables.ps1

You will get the same output as the first one.

Let’s take another example,


Using the env variable at the pwsh (PowerShell Core) level

For the different tasks/scripts, there are different methods to get the environment variable value. Like for the script task, you need to use different methods to get the environment variable values using %VariableName%.

Loading