RousselTMLEARNING

DevOps

Azure YAML pipelines: stages, tasks, variables and templates

Writing Azure pipelines in YAML: trigger and pr triggers, stages, jobs and steps, versioned tasks, variables, variable groups and parameters, the three expression syntaxes, conditions and dependencies, templates (templates and extends), artifacts and cache.

1. A continuous integration pipeline #

azure-pipelines.yml.

The file #

YAML structure
trigger:
  branches:
    include: [main]
pr:
  branches:
    include: [main]

pool:
  name: Default            # self-hosted agent; or vmImage: ubuntu-latest

steps:
  - script: |
      python3 -m venv .venv
      .venv/bin/pip install -r requirements-dev.txt
      .venv/bin/pytest --junitxml=$(Build.ArtifactStagingDirectory)/rapport.xml
    displayName: Tests
  - task: PublishTestResults@2
    condition: succeededOrFailed()
    inputs:
      testResultsFiles: $(Build.ArtifactStagingDirectory)/rapport.xml
      testRunTitle: Shop tests
  - task: PublishPipelineArtifact@1
    inputs:
      targetPath: $(Build.SourcesDirectory)
      artifact: boutique
  • Tasks (PublishTestResults@2) are ready-made actions, versioned by their major number.
  • Predefined variables ($(Build.BuildId), $(Build.SourceBranchName), $(Build.ArtifactStagingDirectory)) describe the run.

2. Variables, expressions and templates #

Parameterize and factor.

Three syntaxes #

SyntaxEvaluatedUse
${{ variables.x }}when the YAML is compiledparameters, structural conditions, templates
$[ variables.x ]at runtime, before the jobconditions and computed variables
$(x)at runtime, in the taskvalues in scripts and task inputs
# templates/deploy.yml
parameters:
  - name: environment
    type: string
  - name: port
    type: number
jobs:
  - deployment: deploy_${{ parameters.environment }}
    environment: ${{ parameters.environment }}
    strategy:
      runOnce:
        deploy:
          steps:
            - script: ./deploy.sh ${{ parameters.environment }} ${{ parameters.port }}

# azure-pipelines.yml
variables:
  - group: shop-common              # variable group (Library)
stages:
  - stage: Staging
    jobs:
      - template: templates/deploy.yml
        parameters: { environment: staging, port: 8081 }
  • Variable groups (Pipelines › Library) share values across pipelines, optionally linked to Azure Key Vault.
  • extends enforces an approved pipeline template: a "required template" check rejects pipelines that do not use it.
Watch out : A secret variable is never passed automatically to scripts: pass it explicitly through env:.

Commands to know #

Commands to know
  • az pipelines create --name boutique-ci --yml-path azure-pipelines.yml : create a pipeline
  • az pipelines run --name boutique-ci : run a pipeline
  • az pipelines variable-group create --name boutique-commun --variables REGISTRE=… : create a variable group
  • az pipelines runs list --top 5 -o table : latest runs

Sources #

Checked in November 2026: CI/CD platforms change every month, check versions and plans in the vendor's documentation.

Related articles

Azure DevOps: services, organization and plans

Discover Azure DevOps: Boards, Repos, Pipelines, Test Plans and Artifacts, organizations and projects, Azure …

Azure Boards and Azure Repos: planning and collaborating

Organizing work with Azure Boards (Agile, Scrum, Basic and CMMI processes, work items, backlogs, sprints, boa…

Azure Pipelines agents: hosted, self-hosted and managed pools

Choosing and running Azure Pipelines agents: Microsoft-hosted agents and images, self-hosted agents (installa…

Keep learning

Support us

♥ SUPPORT US

Support RousselTM Learning

Courses, articles, labs and certificates stay free with no intrusive ads. A voluntary contribution, of any amount you choose, pays for hosting, lab environments and new content.

Contribute with PayPal Any amount · card or PayPal accountLearn more
QR code PayPal
Or scan this QR code with your phone

Thank you, every contribution counts!