AZ-400 Pipeline Variables and Templates 3 — Questions and Answers
Question 1: You want to reuse a YAML template stored in a different Azure DevOps repository. What must you configure first?
- A service connection to the other repository
- A resources.repositories reference with the repository alias (Correct answer)
- A variable group linked to the other project
- An artifact download step before the template reference
Correct answer: A resources.repositories reference with the repository alias
Cross-repository templates require declaring the source repo under `resources.repositories` with a `ref` and `type` before you can reference its templates.
Question 2: What is the syntax to reference a variable set in a previous stage named 'Build' from job 'CompileJob' within a subsequent stage?
- $(Build.CompileJob.outputVar)
- $[stageDependencies.Build.CompileJob.outputs['stepName.outputVar']] (Correct answer)
- ${{ dependencies.Build.outputs['CompileJob.outputVar'] }}
- $(dependencies.Build.CompileJob.outputVar)
Correct answer: $[stageDependencies.Build.CompileJob.outputs['stepName.outputVar']]
Cross-stage output variable references use `$[stageDependencies.StageName.JobName.outputs['stepName.varName']]` runtime expression syntax.
Question 3: Which template parameter type allows passing a sequence of arbitrary values such as a list of environment names?
- string
- boolean
- object (Correct answer)
- number
Correct answer: object
The `object` parameter type accepts YAML sequences and mappings, making it suitable for passing lists or dictionaries to templates.
Question 4: A developer sets `variables: [{name: API_URL, value: https://dev.api.com}]` at the pipeline level and also sets the same variable at the job level to a production URL. Which value is used during job execution?
- The pipeline-level value because it is declared first
- The job-level value because job scope overrides pipeline scope (Correct answer)
- Both values are concatenated
- An error is thrown due to duplicate variable names
Correct answer: The job-level value because job scope overrides pipeline scope
Job-level variable definitions override pipeline-level definitions because narrower scopes take higher precedence in Azure Pipelines.
Question 5: Which Azure CLI command updates a pipeline variable to be secret after the pipeline has already been created?
- az pipelines variable update --name VAR --secret true (Correct answer)
- az devops variable set --secret --name VAR
- az pipelines variable-group update --secret VAR
- az pipelines run --variable VAR:secret
Correct answer: az pipelines variable update --name VAR --secret true
The `az pipelines variable update --name VAR --secret true` command converts an existing pipeline variable to a secret type.
Question 6: What does the `${{ variables.myVar }}` template expression return if `myVar` is a runtime-only variable set by a previous step?
- The current value of myVar at the time the step runs
- An empty string, because template expressions are resolved before runtime (Correct answer)
- A compilation error
- The literal string '${{ variables.myVar }}'
Correct answer: An empty string, because template expressions are resolved before runtime
Template expressions (`${{ }}`) are resolved at compile/queue time, so runtime-only variables are not yet available and result in an empty string.
Question 7: How can you prevent a pipeline consumer from overriding a specific template parameter at queue time?
- Set the parameter as `secret: true`
- Do not expose the value as a parameter; hardcode it inside the template (Correct answer)
- Use the `readonly: true` attribute on the parameter
- Set `allowOverride: false` on the variable group
Correct answer: Do not expose the value as a parameter; hardcode it inside the template
Hardcoding values inside a template rather than exposing them as parameters prevents consumers from overriding those values.
You want to reuse a YAML template stored in a different Azure DevOps repository.
What must you configure first?