AZ-400 Pipeline Variables and Templates 5 — Questions and Answers
Question 1: Which YAML pipeline feature lets you define a reusable set of steps in one file and include them in multiple jobs across different pipelines?
- Step libraries via variable groups
- Step templates referenced with `- template:` inside a `steps:` block (Correct answer)
- Shared artifact pipelines
- Deployment group templates
Correct answer: Step templates referenced with `- template:` inside a `steps:` block
Step templates are YAML files containing a `steps:` list that can be included in any job using `- template: path/to/steps.yml`.
Question 2: What is a key security benefit of using `templateContext` when passing data to a required template?
- It encrypts all variable values before sending them to the template
- It allows the template to validate and restrict what the extending pipeline can configure (Correct answer)
- It grants the template elevated permissions to access Azure resources
- It prevents secret variables from being logged
Correct answer: It allows the template to validate and restrict what the extending pipeline can configure
The `templateContext` property lets the required template inspect and validate properties passed by the consuming pipeline, enforcing security constraints.
Question 3: A pipeline uses a variable group named 'Production-Secrets' that requires approval. At which point in the run is the approval gate triggered?
- When the pipeline YAML is first parsed
- When the stage or job that references the variable group is about to execute (Correct answer)
- When the pipeline is manually queued
- When any step first accesses a variable from the group
Correct answer: When the stage or job that references the variable group is about to execute
Approval gates on protected variable groups are triggered when the stage or job referencing the group is about to begin execution.
Question 4: You need a pipeline parameter that accepts only 'dev', 'staging', or 'prod'. Which parameter definition enforces this constraint?
- type: string with a regex validator
- type: string with `values: [dev, staging, prod]` (Correct answer)
- type: enum with members dev, staging, prod
- type: choice with options dev, staging, prod
Correct answer: type: string with `values: [dev, staging, prod]`
Azure DevOps YAML pipeline parameters support a `values:` list under a `type: string` parameter to restrict accepted inputs to a predefined set.
Question 5: How do you make an output variable from a matrix job available to a downstream job?
- Matrix output variables are not supported in Azure Pipelines
- Reference it using `$[dependencies.JobName.MatrixLeg.outputs['stepName.varName']]` (Correct answer)
- Use `$(JobName_MatrixLeg_varName)` macro syntax
- Aggregate matrix outputs with the `collect:` keyword
Correct answer: Reference it using `$[dependencies.JobName.MatrixLeg.outputs['stepName.varName']]`
Matrix job outputs are referenced downstream using `$[dependencies.JobName.MatrixLegName.outputs['stepName.varName']]`, where the matrix leg name is the strategy key.
Question 6: Which statement about pipeline-level variables defined in the Classic (GUI) editor versus YAML is TRUE?
- Classic pipeline variables cannot be made secret; only YAML supports secrets
- Classic pipeline variables can be set as secret and are accessible as $(varName) in both Classic and YAML pipelines (Correct answer)
- YAML pipelines cannot consume variables defined in the Classic editor
- Classic variables are always higher precedence than YAML-defined variables
Correct answer: Classic pipeline variables can be set as secret and are accessible as $(varName) in both Classic and YAML pipelines
Variables defined in the Classic pipeline editor can be marked secret, and their $(varName) macro syntax works the same way in YAML pipelines that reference them.
Question 7: What is the correct way to pass a variable group into a template as a parameter so the template can reference its variables?
- Pass the variable group name as a string parameter and call `az pipelines variable-group show` inside the template
- Link the variable group directly in the pipeline's `variables:` section; its variables are automatically available inside included templates (Correct answer)
- Use `templateContext.variableGroup` to inject the group
- Export the variable group as a pipeline artifact before the template step
Correct answer: Link the variable group directly in the pipeline's `variables:` section; its variables are automatically available inside included templates
Variable groups linked in the pipeline-level `variables:` section are resolved before execution and their variables are available throughout all included templates without additional passing.
Which YAML pipeline feature lets you define a reusable set of steps in one file and include them in multiple jobs across different pipelines?