Understanding Azure DevOps Pipelines: Environment and variables

On This Page What are Azure DevOps Environments?

April 27, 2026 · 17 min read · Testing Guide

Understanding Azure DevOps Pipelines: Environment and variables

Azure is a Microsoft cloud platform that provides services in computing, storage, networking, database, AI, and DevOps. It enables users to manage systems and applications in the cloud with flexibility and scalability.

Azure DevOps is a set of tools that helps teams automate and manage the package development lifecycle. It supports Continuous Integration and Continuous Deployment (CI/CD) pipelines, integrates with Azure service, and manages different environs for deployment.

This article explains the role of surround and variables in Azure DevOps pipelines, including how they delimit deployment strategies, customize builds, and automate tasks within the line.

What are Azure DevOps Environments?

Azure Environments are used to delimitate and manage the base and deployment target for. These environments help engineer deployment resourcefulness, such as Kubernetes clusters,, or other service, across different stages like,, and.

By structure multi-stage deployments, Azure DevOps Environments simplify the process of define, securing, and tracking application releases. They are logical entities representing the specific targets where applications are deployed.

For example, an environment make & # 8220; Prod & # 8221; could be linked to an Azure Kubernetes Service (AKS) clustering, where the production covering test. After passing tests and blessing, Azure DevOps Pipelines can deploy to this environment, control a hold and systematic liberation.

Read More:

Azure Pipelines Environment Benefits

The key benefits of Azure DevOps Environments include consistent deployments, improved visibility, strong security, and scalable solutions for CI/CD pipelines. Below is a detailed explanation of its vantage.

  • Consistency and Reliability: Azure DevOps Environments ensure consistence across deployment stage such as ontogenesis, try, and production. Each environment is specifically configure for its stage. This prevents environment-specific issues and leads to predictable and reliable.
  • Enhanced Visibility and Tracking: Azure DevOps tracks deployment in detail, include the status, initiator, and change made. This allows teams to supervise deployments effectively. The scheme also maintains deployment log, simplifying troubleshooting and helping team trail progress through the pipeline.
  • Integration with Azure Pipelines: Azure DevOps Environments employment with Azure Pipelines to control deployments across different stages. Teams can apply approval workflow, gates, and protection policies to ensure code move through testing, staging, and product in a structured manner.
  • Approvals and Checks: Azure DevOps Environments support both manual approvals and machine-controlled checks to ensure secure and quality deployments. Manual approving processes give authorized personnel control over deployment to critical environments, while automated cheque ensure deployment converge predefined weather before proceeding.

Read More:

  • Resource Management: Azure DevOps Environments connect to physical and virtual resource like Kubernetes clusters, practical machine, and on-premises host. This control that infrastructure matches deployment needs. Teams can besides define environment-specific configurations and variables and customize each environment for its intended function.
  • Security and Permissions: Role-based access control (RBAC) restricts deployment or modification permissions to authorized users. Moreover, sensitive data, such as connection strings and API keys, is securely store and care through Azure Key Vault, protect critical information during deployments.

Also Read:

  • Compliance and Governance: Azure DevOps Environments help impose organizational policies and standards by maintaining audit trails of all deployment activity. This simplifies compliance audits and reporting and insure all deployment processes align with regulatory and internal requirements.
  • Scalability and Flexibility: Azure DevOps Environments support scalable deployment and can accommodate projects of any sizing. They offer flexible deployment strategies like blue-green deployments, canary releases, and rolling update, which allow teams to adapt to different project requirements and deployment want.
  • Monitoring and Diagnostics: Azure DevOps Environments integrate with tools like Azure Monitor and Application Insights to track application health after deployment. These tools provide real-time execution metrics, error logs, and automated alerts to help teams detect failures or degradations before they affect users.

Read More:

Prerequisites for make Azure DevOps Environments

Before you make and use Azure DevOps Environments, ensure that the next prerequisites are met:

1. Azure DevOps Organization & amp; Project: You necessitate an Azure DevOps account. To define the scope and resources for your environment, create a DevOps labor within your system.

2. Permissions & amp; Role-Based Access Control (RBAC): You must feature Project Administrator or Environment Creator permissions to create surround. If you plan to use deployment blessing, set up the right access policies to clear the needful force.

3. YAML or Greco-roman Release Pipeline: If you & # 8217; re use YAML pipelines, you need to ensure that a valid YAML pipeline exists in your repository. For definitive line, you must configure the Release Pipeline to back deployment to the environments you ’ ve set up.

4. Agent or Deployment Targets (Optional for Certain Environments): Depending on the environment type, postdate the appropriate frame-up:

  • Virtual Machines (VMs): Install the Azure DevOps agent on the target VM and ensure it has internet access to communicate with Azure DevOps.
  • Kubernetes Environments: Set up a Kubernetes cluster, whether it ’ s Azure Kubernetes Service (AKS) or another clustering.
  • Azure Resources: Create service connections to authenticate deployments. Use managed identities or service principals for secure access.

Read More:

How to create Azure DevOps Environments?

Below is a step-by-step usher to help you create and manage Azure DevOps Environments:

Step 1: Access Azure DevOps:

Go to Azure DevOps and log in with your credentials. Choose the organization and project where you require to make the environment.

Step 2: Navigate to Environments

In the left-hand card, click on & # 8220; Pipelines & # 8221;. Under the & # 8220; Pipelines & # 8221; subdivision, clink on & # 8220; Environments. & # 8221;

Step 3: Create a New Environment

On the Environments page, click on the & # 8220; New Environment & # 8221; push.

Enter Environment Details:

  • Name:Provide a gens for your surroundings (e.g., & # 8220; Dev & # 8221;, & # 8220; Test & # 8221;, & # 8220; Prod & # 8221;).
  • Description:Optionally, add a description to provide more context about the environment.

After entering the details, chatter the & # 8220; Create & # 8221; push to create the surroundings.

Step 4: Add Resources to the Environment

Click on the environs you just make to open its details page.

Add Resources:

  • Kubernetes:You can add a Kubernetes imagination if you are deploying to a Kubernetes cluster.
  • Virtual Machines: For VM-based deployments, you can add practical machines.
  • Other Resources: Depending on your deployment targets, you can add former resources like databases, entrepot accounts, etc.

Configure Resource Details:

  • Select or make a service connection that relate to your resource (e.g., Azure subscription, Kubernetes cluster).
  • Provide the necessary details for the resource, such as cluster name, namespace, or VM details.
  • Validate the imagination point and click & # 8220; Create & # 8221; to add the resource to the environment.

Step 5: Target Environment from Deployment Jobs

Define the target environment inside a deployment job in a YAML pipeline. Here ’ s a basic example:

stages: - stage: Deploy jobs: - deployment: DeployApp displayName: `` Deploy Application '' environment: `` Production '' # Target Environment strategy: runOnce: deploy: steps: - script: echo `` Deploying to Production ... ''

Key Components include,

1. Deployment: Specifies that this is a deployment job.

2. Environment: Sets thetarget surroundingsfor deployment.

3. Strategy: Defines how the deployment should happen.

  • The runOnce strategy check the deployment runs once per execution.
  • Early scheme likerolling or blue-greencan be used for advanced deployments.

Step 6: Monitor and Manage Deployments

Use the Environments page to supervise the status of deployments, view history, and access logs. Update or remove resources as ask, and align configurations to reflect change in your base.

Under the Environments tab of the grapevine run details, you can see all surround that were targeted by deployment job of a pipeline run.

What are Azure DevOps Variables?

Azure DevOps variables are key-value pairs used to store and deal dynamical values in a pipeline. They let you to configure build, liberation, and deployment without hardcoding values, making your pipelines more flexible and maintainable.

These variables allow you to externalize settings like connection strings, API endpoints, and feature flag, making your pipelines more flexile and secure. Variables can also store secret, environment-specific values, and dynamically yield datum.

Types of Azure DevOps Variables

Azure DevOps indorse several types of variable to help manage active values across line, environments, and instrument.

  • Pipeline Variables: Defined at runtime for frame and releases.
  • System Variables: Predefined by Azure DevOps (e.g., Build.SourceBranch).
  • Environment Variables: Set within the agent ’ s surround for extraneous creature.
  • Secret Variables: Securely store sensible data, such as API distinguish or passwords.
  • Variable Groups: Collections of related variable shared across pipelines.

Azure Pipelines supports three different fashion to reference variables: Macro syntax, template reflexion syntax, and runtime verbalism syntax.

Each syntax serves a different purpose and has singular scoping and evaluation timing. Below is a crack-up of each.

1. Macro Syntax ($ (variableName)): Used for most standard variable references in scripts, task stimulus, and line settings.

Syntax Example:

variables: myVar: `` Hello World '' steps: - script: echo $ (myVar)

Evaluated before the pipeline runs (at runtime). Works in scripts, tasks, and parameters.

Limitations:

  • Can not be used for setting varying name dynamically.
  • Can not reference secrets directly in scripts (use secrets instead).

2. Template Expression Syntax ($ {{variables.variableName}}): Used inside YAML templates to pass variables dynamically.

Syntax Example:

variable: myVar: `` Hello World '' measure: - script: echo $ {{variables.myVar}}

Evaluated at compile time before bunk the pipeline. Used when expanding templates or expressions.

Limitations:

  • Can not access runtime value.
  • Can not modify variables dynamically during execution.

3. Runtime Expression Syntax ($ [variables.variableName]): Used for conditional logic and active variables within jobs and measure.

Pro tip: Tools like SUSA can handle this autonomously — upload your app and get results without writing a single test script.

Syntax Example:

variables: myVar: `` Hello World '' step: - script: echo $ [variables.myVar]

Evaluated at runtime, allowing for dynamic behavior. Utilitarian for conditional performance and complex expressions.

Limitations:

  • Can not be used inside templates.
  • Must be used in specific property, like condition: statements.

User-defined variables vs System variables vs Environment variables

User-defined variable are custom values set by exploiter to configure application-specific settings while system variable are predefined by Azure DevOps and supply metadata about the pipeline execution. On the other hand, environment variables are linked to the operating system or runtime environment and configure the behavior of tasks and tools during execution.

Each varying serve a distinguishable purpose in optimizing line management.

1. User-Defined Variables

These are custom variables defined by exploiter in pipelines, variable radical, or environment. Used to store application-specific configuration values, such as connection twine, file path, or custom-made settings.

Scope:

  • Can be defined at the pipeline level, job degree, or task level.
  • Can also be delimitate in variable radical for reuse across multiple pipelines.

Examples:

  • Application settings (e.g., appName, apiUrl).
  • Non-sensitive configuration values (e.g., environmentType, buildConfiguration).

How to Define:

In YAML pipeline:

variable: appName: 'MyApp' apiUrl: 'https: //api.example.com '

In the Azure DevOps UI (classic pipeline): Go to Pipelines & gt; Library & gt; Variable Groups or delimit them forthwith in the pipeline editor.

Usage:Accessed using $ (variableName) syntax in tasks or script.

steps: - script: echo `` Application name is $ (appName) ''

2. System Variables

These are predefined variables provided by Azure DevOps that contain information about the grapevine, progress, or release process. Used to access metadata about the pipeline executing, such as build ID, pipeline name, or agent details.

Scope:

  • Automatically uncommitted in all pipelines.
  • Read-only (can not be modified by user).

Examples:

  • Build.BuildId: The unique ID of the build.
  • Agent.OS: The operating scheme of the agent.
  • Pipeline.Workspace: The working directory of the pipeline.

Usage:Accessed using $ (variableName) syntax.

stairs: - script: echo `` Build ID is $ (Build.BuildId) ''

3. Environment Variables

These are variables specific to the operating scheme or runtime surround where the pipeline task are action. Used to configure the behavior of handwriting, tools, or processes running on the agent.

Scope:

  • Available to all tasks running on the agent.
  • Can be overridden or extended by user-defined variable.

Examples:

  • PATH:The system path for executable files.
  • JAVA_HOME:The path to the Java runtime.

Usage:Accessed using the syntax specific to the operating scheme:

Windows:% VARIABLE_NAME %

Linux/macOS: $ VARIABLE_NAME

Example in a script:

steps: - handwriting: echo `` System PATH is $ PATH ''

Using Predefined Variables

Predefined variable in Azure Pipelines are automatically set by the system and provide important setting about the build and deployment environment. These variables are read-only and help to avoid hardcoding values in your scripts.

Here are some key points about predefined variables in Azure DevOps Pipelines:

  • Read-only Nature: Predefined variable can not be modified by the user (except a few like Build.Clean and System.Debug).
  • No Hardcoding Needed: These variables allow you to reference dynamic values, such as itinerary and metadata, without manually position them.
  • Classic Pipelines: Insert these variables directly into task editors; they will automatically resolve to their runtime value during execution.
  • Combining Variables: You can combine predefined variable with custom-defined variables to construct dynamic values, such as naming artifacts or fix up conditional logic.
  • YAML Pipelines: Reference predefined variable by converting the name to uppercase and replacing dit with underscores (e.g., Build.ArtifactStagingDirectory becomes$ (BUILD_ARTIFACTSTAGINGDIRECTORY)).

Example Usage in a YAML Script:

steps: - script: | echo `` Artifacts are be staged in: $ (BUILD_ARTIFACTSTAGINGDIRECTORY) '' displayName: `` Display Artifact Staging Directory ''

This script prints out the directory where flesh artifact are arrange, grant you to cite the same directory in subsequent task without hardcoding its path.

Read More:

How to Set Variables In Azure DevOps Pipeline?

You can set variables in YAML or Classic pipelines, or through the Azure DevOps CLI. Below are the methods for setting variables across different grapevine type.

1. Setting Variables in YAML Pipelines

You can set variables in YAML pipelines within specific subdivision, or dynamically during runtime. Here ’ s how to specify them.

A. Define Variables at the Top Level

You can declare variables at the top of your YAML file expend a variables: block. This is utilitarian for defining values that remain never-ending throughout the pipeline run.

variables: myVariable: `` Hello World '' buildConfiguration: `` Release ''

B. Define Variables Inline with a Job or Step

You can also define variables within a specific job or step. These variables are scoped to that particular subdivision.

jobs: - job: BuildJob variables: jobVariable: `` JobSpecificValue '' step: - playscript: echo `` Job varying value is $ (jobVariable) ''

C. Setting Variables Dynamically Using Logging Commands

Within your handwriting, you can set or update variables during runtime using lumber command. For model, in a Bash script:

echo `` # # vso [task.setvariable variable=dynamicVar;] DynamicValue ''

After this dictation executes, you can reference $ (dynamicVar) later in your pipeline.

2. Setting Variables in Classic Pipelines

When working with Classic (UI-based) pipelines, you can set variables through the web interface. Here ’ s how:

A. Access the Variables Tab

  1. Open your Classic pipeline in Azure DevOps.
  2. Click on theVariablestab. This displays a table of existing variables.

B. Add or Edit Variables

  • Add New Variable: Click on theNew Variablebutton, then cater the variable gens and its value.
  • Mark as Secret: If the variable contains sensitive datum, marking it as a undercover by clicking on the padlock icon. This ensures the value is masked in the logs.
  • Edit Existing Variables: You can update the value of any existing variable directly in the UI.

Example:

3. Setting Variables Using the Azure DevOps CLI

Azure DevOps CLI countenance you handle line and variables from the command line, which can be very useful for automation.

A. Create or Update a Variable for a Pipeline

Use the az pipeline variable create command to add a new variable to a pipeline. You need to provide details such as the variable name, value, and pipeline identifier.

Example Command:

az pipelines variable create -- name myVariable -- value `` Hello World '' \ -- pipeline-id 123 -- org `` https: //dev.azure.com/YourOrganization '' -- protrude `` YourProject ''

This command creates (or updates, if it already exists) a variable named myVariable with the qualify value in the pipeline with ID 123.

B. Working with Varying Groups

If you demand to cope a set of variable together, you can use variable group. To make a variable group utilise the CLI, you might use:

az pipelines variable-group create -- gens `` MyVariableGroup '' \ -- variable var1=Value1 var2=Value2 \ -- org `` https: //dev.azure.com/YourOrganization '' -- protrude `` YourProject

This command make a variable group named & # 8220; MyVariableGroup & # 8221; containing two variables.

How to Integrate Browserstack with Azure Pipelines?

Integrating with Azure Pipelines allows you to run cross-browser and mobile exam on BrowserStack & # 8217; s cloud infrastructure within your CI/CD workflow. This simplifies the execution of (or) tests and automatically reports the resultant to your Azure DevOps dashboard.

You must meet certain essential to desegregate BrowserStack with Azure Pipelines.

Here are the prerequisites for integrating BrowserStack with Azure DevOps:

  • BrowserStack Account & Credentials: You postulate an active BrowserStack account, access key, and, if using features, a Test Management API token.
  • Azure DevOps Organization & Project: Set up your Azure DevOps project and line.
  • BrowserStack Azure DevOps Extension (Optional): Install the BrowserStack extension from the to run automated tests on BrowserStack directly from your Azure DevOps pipelines.
  • Testing Framework Setup: Configure your undertaking to associate to BrowserStack ’ s Automate grid and run automated tests on frameworks like Selenium and Appium.

Once you have met these prerequisites, postdate the steps below to mix BrowserStack with Azure Pipelines:

Step 1: Configure BrowserStack Credentials in Azure DevOps

Create secure pipeline variables (or a service connection) for your BrowserStack certificate. For example, define variable like BROWSERSTACK_USERNAME, BROWSERSTACK_ACCESS_KEY, and, if needed, TEST_MANAGEMENT_API_TOKEN.

In the Azure DevOps portal, navigate toProject Settings & gt; Service connections(if using a service connection) or specify these as underground variables in your pipeline ’ s varying tab.

BrowserStack Extension Setup (Optional but Recommended):

Install the BrowserStack Azure DevOps Extension from the Visual Studio Marketplace. This extension adds specialized tasks for configuration and result reporting, reducing the manual scripting needed.

Step 2: Modify Your Pipeline Configuration

To integrate BrowserStack with Azure Pipelines, update your pipeline configuration using YAML, Classic, or the Azure DevOps CLI. Here ’ s how.

A. Using YAML Pipelines

Update your azure-pipelines.yml file to include BrowserStack tasks. Below is a simplified sample snip:

trigger: - main pond: vmImage: ubuntu-latest measure: - task: BrowserStackConfig @ 0 displayName: 'Configure BrowserStack' inputs: BrowserStackServiceEndPoint: 'YourBrowserStackServiceConnection' - job: DotNetCoreCLI @ 2 displayName: 'Restore Project' stimulant: command: 'restore' - task: DotNetCoreCLI @ 2 displayName: 'Build Project' inputs: bidding: 'build' - task: DotNetCoreCLI @ 2 displayName: 'Run Tests' inputs: dictation: 'test' arguments: ' -- filter FullyQualifiedName\! ~ReportGeneration' env: BROWSERSTACK_USERNAME: ' $ (BROWSERSTACK_USERNAME) ' BROWSERSTACK_ACCESS_KEY: ' $ (BROWSERSTACK_ACCESS_KEY) ' BROWSERSTACK_BUILD_NAME: 'MyBuild- $ (Build.BuildId) ' - task: BrowserStackResults @ 1 displayName: 'Publish BrowserStack Test Results' inputs: browserstackProduct: 'automate' continueOnError: true - task: PublishPipelineArtifact @ 1 displayName: 'Publish Test Report' inputs: targetPath: ./Reports/output.html artefact: 'Build Report '

Explanation:

  • BrowserStackConfig Task: Initializes BrowserStack settings using the service connection or variable values.
  • Test Task: Runs your test retinue and passes BrowserStack-specific environment variables. Adjust the arguing and tryout filtering as per your framework.
  • BrowserStackResults Task: Retrieves screen execution details from BrowserStack to integrate with your pipeline ’ s coverage.
  • Artifact Publishing: Optionally, publish generated reports (HTML, JUnit XML, etc.) for later review.

B. Using Classic Pipelines

Here ’ s how to alter your pipeline configuration using Hellenic pipelines.

1. Create or Edit a Build/Release Pipeline:

  • In your Azure DevOps project, navigate toPipelines & gt; Releases(or Builds for classic pipelines).
  • Add a new task for BrowserStack configuration. If the BrowserStack extension is installed, you will see labor like BrowserStack Configuration or BrowserStack Results.

2. Add Tasks Sequentially:

  • BrowserStack Configuration Task: Configure BrowserStack credentials.
  • Build and Test Tasks: Add chore (e.g., MSBuild, Visual Studio Test) to build your project and run tests. Ensure environment variable for BrowserStack are referenced.
  • Publish Test Results: Use tasks such as Publish Test Results to incorporate output from your BrowserStack test footrace.

3. Define Variables:

  • Set your secret variables via the UI by sail to theVariablestab of your pipeline. Mark sensitive data (like admittance key) as mystery.

C. Using Azure DevOps CLI

You can also grapple pipeline variables and chore using the Azure DevOps CLI for automation or scripting. For example:

az pipelines variable create -- name BROWSERSTACK_USERNAME -- value `` your_username '' \ -- pipeline-id 123 -- org `` https: //dev.azure.com/YourOrganization '' -- project `` YourProject '' az pipelines variable create -- name BROWSERSTACK_ACCESS_KEY -- value `` your_access_key '' \ -- pipeline-id 123 -- org `` https: //dev.azure.com/YourOrganization '' -- project `` YourProject ''

These commands setBROWSERSTACK_USERNAME andBROWSERSTACK_ACCESS_KEYas environment variables within the pipeline. You can then reference these variables in your YAML or Classic pipelines to ascertain sensible info like approach keys is firmly stored and used during pipeline execution.

Step 3: Run and Monitor Your Pipeline

Here ’ s how to run and monitor your Azure DevOps grapevine.

  • Trigger the Pipeline: Commit your changes or manually queue a run. The pipeline will use the BrowserStack job to start a tryout run on BrowserStack ’ s Automate grid.
  • Monitor Execution: View the logarithm in Azure DevOps for step pertain to BrowserStack. The BrowserStackResults task will pull exam condition and may include screenshots or video nexus from BrowserStack.
  • Review Reports: Once completed, survey the test report artifacts write by the line. You can likewise cross-check the BrowserStack dashboard to see detailed test session data.

Talk to an Expert

Conclusion

Azure DevOps accelerates software development with continuous integration (CI) and deployment (CD), where environs and variable are key to managing infrastructure and automation. Mastering environment configuration and pipeline management helps businesses build secure, flexible, and automated CI/CD workflow.

The BrowserStack Azure DevOps integration allows teams to across multiple real browser and devices. It support secure credential management, incorporate with both YAML and Classic pipelines, and provides elaborated with logs, screenshots, and picture recording.

Useful Resources for DevOps

Tags
90,000+ Views

# Ask-and-Contributeabout this topic with our Discord community.

Related Guides

Automate This With SUSA

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed.

Try SUSA Free

Test Your App Autonomously

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.

Try SUSA Free