Study guide

7.3 Reusable Elements: Templates, Parameters & Variables

Microsoft Certified: Azure DevOps Engineer Expert AZ-400

Track your progress as you read

Finished sections get a check mark.

1 Chapter 1: Flow of Work, Traceability & Work Tracking

1.1 Flow of Work, GitHub Flow & Feedback Cycles 1.2 Work Tracking with Azure Boards & GitHub Projects 1.3 End-to-End DevOps Traceability & Quality Tracking

2 Chapter 2: DevOps Metrics, Dashboards & Team Collaboration

2.1 DORA Metrics, Flow Metrics & Dashboard Design 2.2 Lifecycle Metrics Across the Six DevOps Phases 2.3 Work Item Queries, WIQL Charts & Analytics 2.4 Project Documentation: Wikis, Mermaid Diagrams & Release Notes 2.5 Webhooks, Service Hooks & Microsoft Teams ChatOps

3 Chapter 3: Git Branching Strategies & Pull Request Workflows

3.1 Git Branching Models & Strategy Design 3.2 Pull Request Workflows & Merge Strategies 3.3 Branch Policies, Quality Gates & Compliance Restrictions

4 Chapter 4: Repository Management, Optimization & Git Data Operations

4.1 Git LFS Architecture & .gitattributes Tracking 4.2 LFS History Migration, git-fat & File Locking 4.3 Git Repository Scaling, Scalar & Monorepo Governance 4.4 Repository Permissions & Git Tag Governance 4.5 Git Data Recovery & Sensitive-Data Scrubbing

5 Chapter 5: Package Management & Dependency Versioning

5.1 Selecting Package Tools: Azure Artifacts vs. GitHub Packages 5.2 Feed Scoping, Upstream Sources & Pipeline Authentication 5.3 Package Views, Immutability & Quality Promotion 5.4 Dependency Versioning: SemVer, CalVer & Automated Versioning 5.5 Pipeline Artifact Versioning & Artifact Storage Strategy

6 Chapter 6: Pipeline Infrastructure, Agents & Integration

6.1 Selecting a CI/CD Solution: Azure Pipelines vs. GitHub Actions 6.2 GitHub-Azure Pipelines Integration & Hybrid Migration 6.3 Hosted vs. Self-Hosted Agents & Runners 6.4 VMSS Elastic Pools, Container Jobs & Agent Governance 6.5 Pipeline Triggers, Filters & Concurrency Management

7 Chapter 7: YAML Pipeline Architecture & Reusable Elements

7.1 YAML Pipeline Anatomy: Stages, Jobs, Steps & Workspaces 7.2 Job Execution Order: DAG Dependencies, Parallelism & Conditions 7.3 Reusable Elements: Templates, Parameters & Variables 7.4 Variable Groups, Secret Variables & Key Vault Linking 7.5 YAML Environments, Checks & Deployment Approvals

8 Chapter 8: Testing Strategy, Quality Gates & Code Coverage

8.1 Test Strategy Design: Local, Unit & Integration Testing 8.2 Load, Stress & Performance Testing in Pipelines 8.3 Test Execution Tasks, Agents & Results Integration 8.4 Code Coverage Analysis & SonarQube Integration 8.5 Quality Gates, Release Gates & Governance Checks

9 Chapter 9: Modern Deployment Strategies & Zero-Downtime Delivery

9.1 Progressive Delivery: Blue-Green, Canary & Ring Deployments 9.2 Minimizing Downtime: Deployment Slots & Rolling Updates 9.3 Feature Flags with Azure App Configuration & Feature Manager 9.4 Designing the High-Priority Hotfix Path 9.5 Ordered Dependency Deployments, Resiliency & Rollback

10 Chapter 10: Artifact Deployment & Database DevOps

10.1 Containerized Application Delivery: ACR, AKS & Container Apps 10.2 Binary, Web App, Function & Scripted Deployments 10.3 Database DevOps: State-Based & Migration-Based Strategies

11 Chapter 11: Infrastructure as Code (IaC) & Azure Deployment Environments

11.1 Infrastructure as Code Strategy: Bicep, ARM & Terraform 11.2 Desired State Configuration & Azure Machine Configuration 11.3 Azure Deployment Environments (ADE) & Developer Self-Service

12 Chapter 12: Pipeline Maintenance, Health & Modernization

12.1 Pipeline Health, Flaky Tests & Reliability Engineering 12.2 Pipeline Optimization: Caching, Slicing & Concurrency 12.3 Artifact & Build Retention Governance 12.4 Modernizing CI/CD: Classic to YAML Migration

13 Chapter 13: Authentication, Authorization & Identity Governance

13.1 Microsoft Entra Service Principals & Managed Identities 13.2 Service Connections, Workload Identity & Personal Access Tokens 13.3 Azure DevOps Projects, Teams & Permission Evaluation 13.4 Access Levels, GitHub Roles & Outside Collaborators

14 Chapter 14: Secrets Management, Sensitive Data & DevSecOps Scanning

14.1 Azure Key Vault, Secret Variables & Secretless CI/CD 14.2 Security Scanning Strategy, GHAS & Secret Scanning 14.3 CodeQL SAST in Pipelines and Containers 14.4 Software Supply Chain, Container Scanning & Cloud Defender

15 Chapter 15: Telemetry Collection, Azure Monitor & Alerting

15.1 Azure Monitor Architecture, AMA & Data Collection Rules 15.2 Application Insights & Specialized Azure Monitor Insights 15.3 Alerting Rules, Action Groups & GitHub Repository Insights

16 Chapter 16: Telemetry Analysis, Distributed Tracing & SRE Practices

16.1 Distributed Tracing, Application Map & Exception Triage 16.2 KQL Log Analytics, SRE Observability & Error Budgets

7.3 Reusable Elements: Templates, Parameters & Variables

Key Takeaways Explain This Topic AI

YAML templates modularize pipeline logic across step, job, and stage tiers, enabling enterprise governance, compliance enforcement, and cross-team standardization.

Templates can be sourced locally within the repository or externally from centralized governance repositories declared in the resources: repositories: block.

The extends template pattern enforces strict enterprise compliance by requiring application pipelines to inject logic into a predefined organizational template skeleton.

Variable syntax spans three distinct evaluation phases: compile-time template expressions ( ${{ ... }} ), job initialization expressions ( $[ ... ] ), and task runtime macro expansion ( $( ... ) ).

Passing output variables across jobs and stages requires setting isOutput=true via VSO logging commands and referencing them via the dependencies or stageDependencies context.

Last updated: September 2026

7.3 Reusable Elements: Templates, Parameters & Variables

As enterprise organizations scale their adoption of Azure DevOps, maintaining monolithic, copy-pasted pipeline definitions across dozens or hundreds of repositories quickly creates maintenance bottlenecks, security drifts, and compliance violations. A security update to a container scanning tool or a change in artifact signing requirements would require editing hundreds of individual YAML files.

Azure Pipelines provides enterprise-grade modularization mechanisms through YAML Templates , Typed Parameters , and a multi-tiered Variable Evaluation Engine . Mastering these constructs is fundamental to architecting scalable CI/CD pipelines and excelling on the AZ-400 exam.

1. YAML Templates Architecture: Step, Job, Stage, and Extends

Templates allow you to define reusable logic in separate YAML files and include them in multiple pipeline definitions. Templates can be structured at four architectural levels:

Step Templates : Encapsulate a sequence of one or more steps (e.g., configuring an SDK, running SonarQube analysis, signing binaries).

Job Templates : Encapsulate one or more complete jobs (e.g., standard build matrix, container packaging workflow).

Stage Templates : Encapsulate entire stages (e.g., an entire standardized QA deployment and automated verification stage).

Extends Templates (Governance) : Inverts the relationship—rather than an application pipeline importing snippets, the application pipeline extends a centralized enterprise template. This ensures that organizational security gates, scanning, and compliance checks cannot be bypassed by development teams.

Step Template Example (Local Reference)

Consider a reusable step template located at .pipelines/templates/security-scan.yml : # File: .pipelines/templates/security-scan.yml

parameters:

  • name: scanLevel
  • type: string
  • default: 'standard'

values:

  • 'quick'
  • 'standard'
  • 'deep'
  • name: failOnVulnerabilities
  • type: boolean
  • default: true

steps:

  • script: echo "Running vulnerability scan with depth ${{ parameters.scanLevel }}..."
  • displayName: 'Execute Security Scanner'

- ${{ if eq(parameters.failOnVulnerabilities, true) }}:

  • script: echo "Enforcing zero-tolerance security gate..."
  • displayName: 'Verify Security Vulnerability Gate'
  • Consuming the step template in the main azure-pipelines.yml : # File: azure-pipelines.yml

trigger:

- main

pool:

vmImage: 'ubuntu-latest'

jobs:

- job: BuildAndScan

steps:

  • script: echo "Compiling application..."
  • template: .pipelines/templates/security-scan.yml

parameters:

  • scanLevel: 'deep'
  • failOnVulnerabilities: true
  • Centralized Multi-Repository Templates

In enterprise environments, templates are maintained in a dedicated, secure repository owned by the Central DevOps or Platform Engineering team. Application repositories reference this external repository via the resources: repositories: declaration: # File: azure-pipelines.yml (Application Repository)

resources:

repositories:

  • repository: SharedTemplates
  • type: git
  • name: CorePlatform/PipelineTemplates # ProjectName/RepoName
  • ref: refs/heads/main # Branch, tag, or commit

stages:

- stage: Build

jobs:

- job: AppBuild

steps:

  • checkout: self
  • # Reference external template using @<repoIdentifier>
  • template: steps/dotnet-build.yml@SharedTemplates

parameters:

  • buildConfiguration: 'Release'
  • enableTelemetry: true
  • The extends Pattern for Security and Governance

The extends template syntax is a critical AZ-400 architectural pattern. When using extends , the central template controls the execution skeleton of the pipeline, and the child pipeline can only supply approved parameters or inject steps into designated hook points. # Central Governance Template: CoreGovernance/templates/secure-pipeline.yml

parameters:

  • name: buildSteps
  • type: stepList
  • default: []

stages:

- stage: ComplianceAndBuild

jobs:

- job: MandatorySecurityScan

steps:

  • script: run-mandatory-org-audit.sh
  • displayName: 'Mandatory InfoSec Audit'
  • job: DeveloperBuild
  • dependsOn: MandatorySecurityScan

steps:

  • # Developer build steps injected here
  • ${{ parameters.buildSteps }}
  • # Central mandatory post-build validation
  • script: upload-sbom-to-central-audit.sh
  • displayName: 'Upload SBOM' # Application Repository azure-pipelines.yml using extends

resources:

repositories:

  • repository: GovernanceRepo
  • type: git
  • name: InfoSec/EnterpriseTemplates

extends:

template: templates/secure-pipeline.yml@GovernanceRepo

parameters:

buildSteps:

  • script: dotnet build
  • script: dotnet test
  • 2. Template Parameters: Types, Validation, and Compile-Time Logic

Parameters are defined at the top of a template or root pipeline. Unlike variables, parameters are strongly typed , evaluated strictly at compile time , and validated before the pipeline begins execution.

Supported Parameter Types

string : Free-form text (can be constrained using a values enumeration list).

number : Numeric values.

boolean : true or false .

object : Complex YAML structures, arrays, or key-value dictionaries.

step / stepList : A single step or a list of steps injected dynamically.

job / jobList : A job or list of jobs.

stage / stageList : A stage or list of stages.

Parameter Validation

Parameters support explicit validation rules using the values keyword to enforce allowed options: parameters:

  • name: environmentName
  • displayName: 'Deployment Environment Target'
  • type: string
  • default: 'Development'

values:

  • 'Development'
  • 'Testing'
  • 'Staging'
  • 'Production'

If a pipeline run is triggered with a value outside this allowed list, Azure Pipelines fails during compile-time validation before any agent is provisioned.

3. Variable Evaluation Phases: Compile-Time vs. Runtime

A frequent source of bugs and exam questions is conflating variable syntaxes. Azure Pipelines evaluates variables across three distinct operational phases: [ Phase 1: Compile Time ] ──► [ Phase 2: Job Initialization ] ──► [ Phase 3: Task Execution ]

  • Syntax: ${{ ... }} Syntax: $[ ... ] Syntax: $( ... )
  • Template Parsing & Parsing Agent Scheduling & Conditions In-Task Macro Expansion
  • Detailed Variable Syntax Comparison Matrix

Syntax Name / Mechanism Evaluation Timing Primary Context / Location Handles Secrets?

${{ <expression> }} Template Expression Compile time (before pipeline runs) Template insertion, loops ( ${{ each }} ), conditional blocks ( ${{ if }} ), parameter parsing No (Secrets do not exist at compile time)

$[ <expression> ] Runtime Expression Job initialization time Stage/job condition: , job-level variables: definitions, output variables from prior jobs No (Not expanded into secret text)

$( <variableName> ) Macro Syntax Task execution runtime (immediately prior to step start) Task inputs, step display names, environment variables Yes (Secrets are injected and masked in logs)

Common Syntactic Pitfalls

Trying to read a secret via template syntax ${{ ... }} : At compile time, secrets have not been decrypted or fetched from Key Vault. Using ${{ variables.secretKey }} produces an empty string.

Using macro syntax $( ... ) in a condition expression : The pipeline parser does not expand macros inside expression functions like eq(...) . Writing condition: eq('$(Build.SourceBranch)', 'refs/heads/main') will evaluate the literal text '$(Build.SourceBranch)' . You must write condition: eq(variables['Build.SourceBranch'], 'refs/heads/main') .

Expecting compile-time loops to iterate over runtime output : Template loops ( ${{ each item in ... }} ) execute only once when the YAML file is parsed into memory. They cannot iterate over lists generated dynamically by earlier build steps.

4. Passing Output Variables Across Steps, Jobs, and Stages

A pipeline often needs to dynamically compute a value in one step (e.g., an image tag, a release version, an Azure resource ID) and consume it in downstream steps, jobs, or stages.

Mechanism 1: Step-to-Step Within the Same Job

To pass a variable to subsequent steps within the same job, output an Azure DevOps logging command to standard out: echo "##vso[task.setvariable variable=DYNAMIC_VERSION]1.4.2"

In the next step on the same agent, access it as $(DYNAMIC_VERSION) or via the environment variable $DYNAMIC_VERSION .

Mechanism 2: Job-to-Job Within the Same Stage

To pass an output variable to a downstream job within the same stage:

The producing step must set isOutput=true .

The producing step must define a name: attribute .

The consumer job must declare a dependency on the producer job using dependsOn .

The consumer job maps the variable at the job level using runtime expression syntax: $[ dependencies.<JobName>.outputs['<StepName>.<VariableName>'] ] . jobs:

- job: ProducerJob

steps:

  • script: |
  • BUILD_HASH=$(git rev-parse --short HEAD)
  • echo "##vso[task.setvariable variable=appHash;isOutput=true]$BUILD_HASH"
  • name: VersionStep
  • displayName: 'Generate Version Hash'
  • job: ConsumerJob
  • dependsOn: ProducerJob

variables:

  • # Map output variable using dependencies context
  • computedHash: $[ dependencies.ProducerJob.outputs['VersionStep.appHash'] ]

steps:

  • script: echo "Received build hash from producer: $(computedHash)"
  • Mechanism 3: Stage-to-Stage Across Stages

To pass an output variable across stage boundaries:

The producing step sets isOutput=true and has a name: attribute.

The consumer stage specifies dependsOn: <ProducerStage> .

The consumer job inside the downstream stage maps the variable using the stageDependencies context: $[ stageDependencies.<ProducerStage>.<ProducerJob>.outputs['<StepName>.<VariableName>'] ] . stages:

- stage: BuildStage

jobs:

- job: BuildJob

steps:

  • script: |
  • CLUSTER_IP="10.240.0.45"
  • echo "##vso[task.setvariable variable=targetIp;isOutput=true]$CLUSTER_IP"
  • name: NetworkStep
  • displayName: 'Discover Target IP'
  • stage: DeployStage
  • dependsOn: BuildStage

jobs:

- job: DeployJob

variables:

  • # Map cross-stage output variable
  • serverIp: $[ stageDependencies.BuildStage.BuildJob.outputs['NetworkStep.targetIp'] ]

steps:

  • script: echo "Deploying payload to destination IP: $(serverIp)"
  • 5. Realistic Exam Scenarios & Common Traps
  • Scenario: Enforcing Enterprise Security Compliance via Extends

Context : An enterprise financial institution with 150 development teams mandates that every container image built in Azure Pipelines must undergo static vulnerability scanning with Prisma Cloud and generate an SBOM using Syft. Developers frequently edit their azure-pipelines.yml files to comment out scanning steps when deadlines approach. Solution : Transition the organization from step templates to the extends template pattern . Define a centralized template in an administrative repository ( InfoSec/ComplianceTemplates ). In the root application repositories, restrict pipeline definitions so they can only provide parameters to extends: template: secure-build.yml@ComplianceTemplates . Developers cannot modify the sequence of stages, ensuring compliance scans execute before any image is pushed to the container registry.

Common Exam Traps to Avoid

Trap: Omitting name: on the step generating an output variable. When calling ##vso[task.setvariable ...;isOutput=true] , if the step lacks a name: attribute (e.g., name: OutputStep ), the output variable will not be registered in the job's outputs dictionary, causing downstream jobs to read empty values.

Trap: Conflating dependencies and stageDependencies . Within the same stage, downstream jobs reference dependencies.<Job>.outputs[...] . Across different stages, you must use stageDependencies.<Stage>.<Job>.outputs[...] .

Trap: Attempting to evaluate runtime variables at compile time. If you write ${{ if eq(variables['Build.SourceBranch'], 'refs/heads/main') }} , template expressions are evaluated before the branch context is established during queuing. Use condition: eq(variables['Build.SourceBranch'], 'refs/heads/main') instead.

Loading diagram... Variable Evaluation Lifecycle & Cross-Stage Output Propagation