← Back to Articles         
Azure DevOps: Pipeline Variables vs Parameters

Azure DevOps: Pipeline Variables vs Parameters

Published on 08 Oct 2026     6 min read Azure DevOps
YAML Pipelines

1. What are Pipeline Variables and Parameters?

In Azure DevOps YAML Pipelines, variables and parameters are used to make pipelines configurable, reusable, and dynamic.

Instead of hardcoding values such as environment names, build configurations, and project paths, we can define them separately and reuse them.

  • Variables: Store configuration values used during pipeline execution. Some variables can be modified while the pipeline runs.

  • Parameters: Define input values that are resolved before pipeline execution, during template expansion. They cannot be modified during execution.

Real-time example:

Suppose we have an ASP.NET Core Web API application that needs to be built and deployed to three environments:

  • Development (DEV)

  • User Acceptance Testing (UAT)

  • Production (PROD)

We can use a parameter to select the deployment environment and variables to configure the build.

2. What are Pipeline Variables?

Pipeline variables are named values that store information such as build configuration, application name, project path, and environment settings.

YAML example

trigger:
- main

variables:
  buildConfiguration: 'Release'
  applicationName: 'MyWebAPI'

pool:
  vmImage: 'ubuntu-latest'

steps:
- script: |
    echo "Build: $(buildConfiguration)"
    echo "Application: $(applicationName)"

Explanation:

Property

Description

variables:

Defines pipeline variables

buildConfiguration

Stores Release

applicationName

Stores MyWebAPI

$(variableName)

Macro syntax to access variables

Output:

Build: Release
Application: MyWebAPI

Can variables change during execution?

Yes. Mutable variables can be updated using the task.setvariable logging command.

steps:
- script: |
    echo "##vso[task.setvariable variable=appVersion]2.0"
  displayName: 'Set Version'

- script: |
    echo "Version: $(appVersion)"
  displayName: 'Display Version'

Output:

Version: 2.0

The updated variable is available to subsequent steps in the same job.

Types of pipeline variables

Type

Purpose

User-defined variables

Defined in YAML or pipeline settings

System variables

Predefined by Azure DevOps

Secret variables

Securely store passwords, tokens, and secrets

Variable groups

Share variables across multiple pipelines

Output variables

Pass values between steps, jobs, or stages

For example, $(Build.BuildId) is a predefined system variable.

3. What are Pipeline Parameters?

Pipeline parameters allow users to provide input values when starting a pipeline.

Parameters support data types such as string, boolean, number, object, step, and stepList.

YAML example

parameters:
- name: environment
  displayName: 'Select Environment'
  type: string
  default: 'dev'
  values:
  - dev
  - uat
  - prod

steps:
- script: |
    echo "Environment: ${{ parameters.environment }}"

Explanation:

Property

Description

parameters:

Defines parameters

name:

Parameter name

displayName:

Name displayed in the Run Pipeline UI

type:

Data type

default:

Default value

values:

Allowed values

When you manually run this pipeline, Azure DevOps displays a dropdown:

Run Pipeline
    |
    v
Select Environment
    |
    +---- dev
    |
    +---- uat
    |
    +---- prod
    |
    v
Click Run

If you select uat, the output is:

Environment: uat

Important: Parameters cannot be modified after the pipeline starts.

4. Difference Between Variables and Parameters

Feature

Variables

Parameters

Purpose

Store configuration values

Configure pipeline execution

Syntax

$(variableName)

${{ parameters.name }}

Evaluation

Depends on expression syntax; macro values are resolved before tasks

During template parsing

Change during execution

Yes, if mutable

No

Data types

Strings

String, number, boolean, object, etc.

Secret support

Yes

No

Default values

Supported

Supported

User selection

Supports overridable values

Supports predefined dropdown choices

Conditional stages

Can be used in conditions

Can control template structure

Common usage

Build settings, versions, secrets

Environment selection, optional stages

5. Real-Time Example: ASP.NET Core Web API

Consider a .NET Web API project that must be built in Release mode and deployed to DEV, UAT, or PROD.

trigger:
- main

parameters:
- name: environment
  displayName: 'Select Environment'
  type: string
  default: dev
  values:
  - dev
  - uat
  - prod

variables:
  buildConfiguration: 'Release'
  projectPath: 'src/MyWebAPI/MyWebAPI.csproj'

pool:
  vmImage: 'ubuntu-latest'

steps:
- task: DotNetCoreCLI@2
  displayName: 'Build Web API'
  inputs:
    command: 'build'
    projects: '$(projectPath)'
    arguments: '--configuration $(buildConfiguration)'

- script: |
    echo "Environment: ${{ parameters.environment }}"
    echo "Configuration: $(buildConfiguration)"
  displayName: 'Display Configuration'

How does it work?

Developer
    |
    v
Run Azure Pipeline
    |
    v
Select Environment (Parameter)
    |
    +---- dev
    +---- uat
    +---- prod
    |
    v
Template Expansion
    |
    | Resolve ${{ parameters.environment }}
    |
    v
Start Pipeline Execution
    |
    v
Read Variables
    |
    | buildConfiguration = Release
    | projectPath = MyWebAPI.csproj
    |
    v
Build ASP.NET Core Web API
    |
    | dotnet build -c Release
    |
    v
Display Selected Configuration
    |
    v
Pipeline Completed

This example builds the application and displays the selected environment. Actual deployment requires additional tasks or stages.

6. Variable Expression Syntax

Azure DevOps supports three important variable expression syntaxes.

Syntax

Evaluation time

Example

Macro

Before each task runs

$(buildConfiguration)

Template expression

During template expansion

${{ variables.buildConfiguration }}

Runtime expression

During runtime expression evaluation

$[variables.isMain]

Example:

variables:
  buildConfiguration: 'Release'

steps:
- script: |
    echo "$(buildConfiguration)"
    echo "${{ variables.buildConfiguration }}"

Both print Release in this example.

However, if the variable changes during execution, macro syntax can reflect the updated value in subsequent tasks, while template expressions retain their earlier resolved value.

7. Advantages and Disadvantages

Variables

Advantages

  • Reuse configuration values.

  • Support secrets and variable groups.

  • Can be updated during execution.

  • Support environment-specific configuration.

Disadvantages

  • Values are stored as strings.

  • Different evaluation syntaxes can cause confusion.

  • Scope and variable precedence must be understood.

Parameters

Advantages

  • Support multiple data types.

  • Provide dropdown selections.

  • Support conditional stages, jobs, and steps.

  • Make reusable YAML templates easier to configure.

Disadvantages

  • Cannot change during execution.

  • Cannot securely store secrets.

  • Values are resolved before pipeline execution.

8. Important Interview Questions and Answers

Q1. What is the main difference between variables and parameters?

Variables store configuration values used during pipeline execution, whereas parameters provide inputs resolved before execution during template parsing.

Q2. Can we modify a parameter during execution?

No. Parameters are immutable after the pipeline starts.

Q3. Can variables change during execution?

Yes. Mutable variables can be updated using task.setvariable.

Q4. Can we store passwords in parameters?

No. Use secret variables, variable groups, or Azure Key Vault integration.

Q5. When should we use parameters instead of variables?

Use parameters when selecting environments, enabling or disabling stages, or supplying typed inputs before execution.

Q6. Can variables and parameters be used together?

Yes. Real-world pipelines commonly use both. For example, a parameter selects the deployment environment, while variables store build configurations and project paths.

Q7. What is the difference between $(variable) and ${{ parameters.name }}?

$(variable) uses macro syntax and is expanded before a task runs. ${{ parameters.name }} is evaluated during template expansion before pipeline execution.

9. Key Points for Interview

  • Variables = Configuration values.

  • Parameters = Pipeline inputs and structural control.

  • Variables commonly use $(name).

  • Parameters use ${{ parameters.name }}.

  • Variables may change during execution.

  • Parameters cannot change during execution.

  • Variables support secrets; parameters do not.

  • Use parameters for environment selection and conditional pipeline structure.

Interview-ready answer

"In Azure DevOps, variables and parameters make YAML pipelines reusable and configurable. Variables store values such as build configuration, application version, and secrets. They can be evaluated and updated during pipeline execution. Parameters are evaluated during template parsing, support different data types, and cannot be changed after the pipeline starts. We generally use parameters to control pipeline behavior and variables to manage configuration values."

Official documentation: Azure DevOps Runtime Parameters | Azure DevOps Variables

← Back to Articles