AZ-401: Reusable YAML Templates Variables and Classic Task Groups
Choose the reuse mechanism by its pipeline surface and evaluation time. In Azure Pipelines YAML (YAML Ain’t Markup Language), include templates insert shared content, while extends templates define the structure a consuming pipeline follows. Use typed parameters for explicit early inputs and variables for configuration values. In Classic pipelines, create a project-scoped task group from an existing task sequence. A Key Vault-linked variable group maps selected secret names and retrieves their current values at runtime; it is a separate configuration operation.
Implement these choices in an owned nonproduction definition, inspect the expanded behavior and affected consumers, and preserve a restoration path before accepting the change. The following procedures and marker examples are illustrative; no pipeline, task group, secret operation or cloud configuration was executed here. Complete AZ-401: YAML Triggers Job Dependencies and Parallel Execution first so reuse does not obscure the graph, events and execution permissions.
Select the surface and preserve its baseline
Record the source revision, current definition, owners, existing inputs and consumers. Preserve the original YAML files or full Classic definition using the owner's approved backup method. Keep existing trigger and permission controls; adding shared logic is not permission to broaden admission or resource access.
| Need | Mechanism | Verification boundary |
|---|---|---|
| Repeat steps, jobs or stages in Azure YAML | Include a matching template | The inserted content and explicit inputs produce the intended graph |
| Supply an Azure pipeline's permitted structure | Extend a base template | The consumer follows that structure; independent resource checks remain separate |
| Reuse nonsecret configuration text | A variable-only template | Values are available at the evaluation point where they are referenced |
| Reuse tasks in Classic | A project task group | Its inputs, references and selected version are understood |
| Retrieve selected existing vault secrets | A linked variable group | Name mapping, runtime access and network conditions are verified |
The YAML exercise assumes an authorized Azure DevOps project and existing execution capacity. The Classic exercise uses a separate owned preserved Classic copy. The vault exercise requires an existing compatible vault, service connection and owner-prepared authorized consumer. These are separate prerequisites, not resources created implicitly by one template.
Implement a typed YAML include
Place the example templates in the selected source checkout so they are available when the pipeline starts. A template cannot be supplied later as a pipeline artifact. The following files demonstrate nonsecret marker content; merge the consumer elements into the owned definition while retaining its reviewed event controls.
First, define a variable-only file named templates/shared-vars.yml:
variables:
markerText: shared-marker
Next, define templates/marker-steps.yml with explicit input types:
parameters:
- name: message
type: string
default: shared-marker
- name: showDetail
type: boolean
default: false
steps:
- script: echo "$MARKER_TEXT"
env:
MARKER_TEXT: ${{ parameters.message }}
- ${{ if eq(parameters.showDetail, true) }}:
- script: echo "Detail marker"
Use it in the root consumer's relevant configuration:
pool:
vmImage: ubuntu-latest
variables:
- template: templates/shared-vars.yml
steps:
- template: templates/marker-steps.yml
parameters:
message: ${{ variables.markerText }}
showDetail: true
The variable-only include defines configuration; the step include supplies executable content. Its Boolean parameter controls whether the detail step is inserted. Keep the marker an owner-reviewed nonsecret value; passing text through an environment variable avoids inserting that text directly into a shell program. A parameter's declared type still does not authorize the resulting action.
Review both the consumer and included file at the same selected revision. Relative template paths are resolved from the including file, so a move can change what a reference means. Check exact paths and input names before diagnosing execution failures.
Use extends when the base owns the structure
For the alternative layout, put the job structure in templates/base.yml. It can reuse the same step template through its relative path:
parameters:
- name: message
type: string
default: shared-marker
- name: showDetail
type: boolean
default: false
jobs:
- job: ReusableMarker
pool:
vmImage: ubuntu-latest
steps:
- template: marker-steps.yml
parameters:
message: ${{ parameters.message }}
showDetail: ${{ parameters.showDetail }}
The corresponding root consumer elements are:
variables:
- template: templates/shared-vars.yml
extends:
template: templates/base.yml
parameters:
message: ${{ variables.markerText }}
showDetail: true
Use this as an alternative consumer, rather than appending it to the previous root steps example. The base now supplies the job and the consumer supplies its supported inputs. This small example demonstrates structure reuse; it does not itself establish a mandatory organization-wide template policy or an environment approval. Those admission and resource-owner controls require separate configuration.
Inspect expansion separately from runtime values
Parameters expand early, so not every variable is available to select template structure. A variable-only template can provide the static marker used above. A value that will arrive from a later task or a vault lookup is not automatically available during that early expansion.
Before accepting the change, compare the processed job and its step list with the expected expansion. On the owned nonproduction pipeline, retain the actual source revision and platform evidence:
- With
showDetailset to Booleantrue, the processed job should contain the marker step followed by the detail step. - In a separately reviewed test change, set it to Boolean
false. The detail step should be absent from the expanded job, rather than merely present with a runtime skip. - Inspect the marker step's resolved nonsecret input and actual output if the owner authorizes a run. A successful YAML parse alone does not prove that Azure expanded the intended template or executed it.
Keep parameter types explicit. The template documentation warns that an untyped nonempty string can be treated as true in a Boolean context, even when its text says false. Review the input type and expansion instead of relying on a visually familiar value.
Macro references such as $(markerText) are a different use of variables from the early template expression shown above. Record which values are needed to construct the graph and which are required only when work runs. Do not pass a runtime-only secret into an early structural decision or print it to discover when it becomes available.
Create the Classic task group on an owned copy
Task groups apply to Classic build and release pipelines and are stored within the project. They do not become YAML templates. Start from an existing owned Classic copy containing a small approved task sequence whose effects are understood; preserve its entire definition and linked inputs before changing it.
- Identify the task inputs that should vary. Express those inputs with variables, such as
$(MarkerName), and record their intended nonsecret defaults. Literal or empty inputs can become fixed rather than exposed group parameters. - Inspect linked parameters across the pipeline. The documented Unlink all action is in the pipeline settings panel and affects the pipeline, so evaluate its full scope on this preserved copy before selecting it and confirming. Stop if the links cannot be restored or the definition has shared ownership.
- Select the intended task sequence, open its context menu and choose Create task group. Supply a descriptive name, description and task-catalog category, then select Create.
- Inspect the replacement task group in the copy. Variable references from underlying tasks, except predefined variables, surface as group parameters. Review every exposed parameter, its default and the values passed by the consumer; preserve task conditions as well.
- Save the updated owned pipeline. Compare the resulting group invocation with the original sequence, including task order, fixed inputs, variable inputs and conditions.
Under Pipelines, open Task groups, then the new group's details. Inspect References for pipelines and other groups that use it and History for its actual changes. Record the selected version in the owned pipeline. If References reveals an unexpected consumer, stop changes and return the impact decision to the owner.
Verify version propagation before changing shared consumers
A direct save of an existing group's edit is a minor update. Consumers of that major version pick up the change automatically; their displayed selection can remain 1.*. Selecting that same major version again is not proof that the old task content has been restored.
For a controlled version exercise, change only the owned test group and choose Save as draft. The documented workflow offers Publish draft and Publish as preview; select the preview version explicitly in the owned test pipeline and verify its parameters and actual behavior. Inspect History and References again. After validation and owner approval, Publish preview makes that version production-ready. Existing consumers must explicitly select a new major version, while newly added task groups default to the highest non-preview version.
Treat the version choice as an impact decision. A passing run on one copy does not demonstrate that every referenced pipeline is compatible. For a minor-update test, use the documented separate draft group in the test pipeline before deciding whether the same change should propagate through a direct save.
Restore the owned pipeline's previous sequence, links, inputs and version selection from the preserved baseline. Compare content as well as the version caption. Before deleting an owned temporary group or draft, inspect References and confirm that no other consumer depends on it. The group menu's Delete action requires confirmation; it is not a way to undo changes already propagated to another definition.
Configure an existing-vault linked variable group
Use an existing Azure Key Vault and an existing Azure Resource Manager service connection in the project. The operator needs at least Creator permission in Library to create the group and the User role for the service connection. Confirm the connection's actual vault access with its owner; the subscription Owner requirement for creating a new vault is outside this procedure.
For this integration, role-based access control (RBAC) vaults must be accessible through a public endpoint. RBAC vaults behind private endpoints are unsupported in the assigned Azure DevOps integration, and Azure DevOps is not currently an Azure trusted service for that path. Verify the actual network restrictions and service-connection access. Do not disable network protections or switch the vault's permission model simply to complete this exercise; return an incompatible setup to the vault owner.
For a supported public-endpoint RBAC vault, the source identifies Key Vault Secrets User or Key Vault Secrets Officer, according to the scenario, for the service connection. Use the owner-approved least-permission choice and confirm the secret-read requirements. The documented access-policy path separately uses Get and List secret permissions; do not treat an access-policy screen as the configuration method for an RBAC vault.
Create only the linked group:
- In the selected Azure DevOps project, open Pipelines, Library, then + Variable group.
- Enter a name and optional description. Enable Link secrets from an Azure key vault as variables.
- Select the approved service connection and choose Authorize. Select the existing vault; use its displayed authorization control where the applicable permission-model path requires it.
- Choose + Add, select the approved existing secret names, confirm the selection with OK, and select Save.
- Reopen the saved group and compare the service connection, vault and selected names with the approved record. Preserve name and access evidence without copying secret values.
Only names are mapped into the group. Current values are fetched from the vault when a linked pipeline runs. A change to an already mapped secret value becomes available to consumers, but adding or deleting a vault secret does not automatically update the selected name set. Explicitly revisit that mapping. Keys and certificates are not supported by this variable-group integration.
Use an existing owner-authorized consumer whose group linkage is already established to verify the runtime boundary. Confirm retrieval through an approved check that does not reveal the secret. Record the mapped name, relevant nonsecret version/access evidence, and the actual success or failure. Group creation alone does not prove that the consumer can retrieve its values. This procedure supplies no generic consumer YAML, creates no vault or credential, and does not turn runtime values into early template parameters.
Evaluate failures and restore only owned changes
Use the following distinctions during an authorized exercise; they describe expected evidence to collect, not observations obtained here.
| Symptom | Evidence and next decision |
|---|---|
| A template reference cannot expand | Check its selected revision, path, declared input types and variable availability before changing execution permissions |
| Detail remains in the job after a false input | Inspect the actual typed value and processed step list; distinguish expansion from runtime conditions |
| A Classic edit affects another pipeline | Inspect References, History and selected versions; preserve the propagated change and involve that consumer's owner |
| A group maps a name but retrieval fails | Check the existing connection, permission model, supported endpoint and secret access without printing the value |
| A newly added vault secret is missing from the group | Inspect and explicitly update the selected name mapping; value refresh does not add names |
Restore only the temporary YAML consumer edits, Classic copy changes and group mappings introduced for the exercise. Keep shared template files, existing service connections and unrelated consumers intact. If a new test group is no longer needed, its owner should retire it through the existing controlled process after checking its consumers; this is not vault deletion or credential revocation.
For GitHub Actions, retain its own workflow files, event configuration, job dependencies and token-permission rules. The current workflow-syntax reference supports that organization and distinguishes reusable-workflow job calls, but an Azure include or Classic task group is not a GitHub recipe. Do not transplant the Azure examples. Keep any GitHub reuse implementation within its separately verified syntax and actual repository restrictions.
Review reusable logic as executable input, including changes received through shared definitions. GitHub's secure-use guidance warns that secret redaction is not guaranteed and that untrusted execution can compromise a runner. Use nonsecret markers for these examples and preserve the real trust and credential boundaries. Vault integration details continue in AZ-401: Key Vault Integration with Azure Pipelines and GitHub Actions; independent resource checks remain separate from reuse.
Authoritative Sources
- Use YAML templates in pipelines for reusable and secure processes — include/extends, typed parameters, variable-only templates, paths and early expansion.
- Task groups in Classic pipelines — parameter extraction, creation, linked-input scope, References, History and version propagation.
- Link a variable group to secrets in Azure Key Vault — existing vault/connection setup, Library roles, runtime mapping and supported network/permission conditions.
- Key Azure Pipelines concepts — the pipeline, stage, job and step execution model.
- Workflow syntax for GitHub Actions — GitHub workflow organization, reusable-workflow job calls and permission boundaries.
- Secure use reference — untrusted execution, least privilege and limits of secret redaction.

