Microsoft Certified: DevOps Engineer ExpertDesign and implement pipelinesMedium
A team uses Azure Pipelines (YAML) for their CI/CD. They have a complex deployment process that involves several stages: 'Build', 'Test', 'StagingDeployment', and 'ProductionDeployment'. The 'StagingDeployment' and 'ProductionDeployment' stages share a significant amount of identical configuration and steps, but with different environment-specific variables. The team wants to reduce duplication and improve maintainability of their pipeline definitions. Which YAML feature should they use?
- AConditions
- BDependencies
- CTemplates
- DVariable groups
Show answer & explanationAnswer & explanation
Correct answer: C. Templates
YAML templates in Azure Pipelines allow you to define reusable content (like stages, jobs, or steps) in separate YAML files. This is ideal for scenarios where multiple stages or pipelines share common structures but need to be parameterized with environment-specific variables, significantly reducing duplication and improving maintainability.
Why the other options are wrong
- A. Conditions are used to control when a stage, job, or step runs, not for abstracting and reusing common pipeline definitions.
- B. Dependencies define the order of execution between stages or jobs, not for code reuse or reducing duplication.
- D. Variable groups are for sharing variables, not for reusing entire blocks of pipeline structure like stages or jobs.
YAML Templates (Azure Pipelines)
Reusable YAML files that define common pipeline structures (stages, jobs, steps) which can be parameterized and included in multiple pipelines or stages.
- Reduces duplication in complex pipeline definitions.
- Improves maintainability and consistency across pipelines.
- Supports parameterization for environment-specific configurations.
Memory trick: Templates are like cookie cutters for your YAML code.