Reusable pipelines, environments and approvals

AZ-400 DevOps EngineerBuild and release pipelinesAbout 20 minutesBy Cloud Hands On

YAML templates, task groups, variables and variable groups, environments with checks, and moving from classic to YAML.

In this lesson you'll learn

1. Templates

YAML templates are files you include from other pipelines, with parameters. There are step, job, stage and variable templates. An extends template wraps the whole pipeline, so an organisation can require that every pipeline runs, for example, a security scan stage; the required template check on an environment enforces it. Templates can live in another repository, referenced through resources: repositories:.

In GitHub Actions the equivalents are reusable workflows (workflow_call) and composite actions.

2. Task groups and variables

Task groups bundle steps for reuse in classic pipelines; in YAML, use templates instead.

Variables can be set in YAML, in the pipeline settings (and marked secret), at queue time, or in variable groups in the Library, which many pipelines share. A variable group can be linked to Azure Key Vault, so secrets come from the vault at run time. Variables use $(name) at run time and ${{ variables.name }} at compile time.

3. Environments, approvals and checks

An environment (such as test or production) records every deployment to it, and holds the approvals and checks that must pass before a deployment job targeting it starts. Because the checks belong to the environment, a pipeline author can't remove them by editing YAML. Deployment jobs use environment: production and a strategy (runOnce, rolling or canary).

GitHub has environments too: required reviewers, wait timers, deployment branch rules and environment secrets.

4. Classic to YAML

Classic build and release pipelines are edited in the browser; YAML pipelines are code, reviewed in pull requests and versioned with the app. To migrate, use Export to YAML (or View YAML on jobs) as a starting point, replace task groups with templates, move release stages into stages with deployment jobs, recreate approvals and gates as environment checks, and move variables into variable groups.

Example

Fernhill Cloud writes one stage template, deploy-webapp.yml, used by 30 product pipelines. The production environment has the required template check, so a pipeline can only deploy to production through that template, which always includes the vulnerability scan.

Exam traps to remember

  • Task groups are classic only; YAML uses templates.
  • Link a variable group to Key Vault to pull secrets at run time.
  • Environment checks can't be bypassed by editing the YAML file.

Test yourself: 3 check questions and exam-style practice questions on this topic are in the AZ-400 DevOps Engineer app.

Practise in the app

Keep going