Safeguard
Developer Tools•

Azure Pipelines templates: what do extends and includes change?

In Azure Pipelines, an extends template fixes the pipeline structure while an includes template inserts steps. Which to use when adopting shared templates.

Safeguard Security Team
3 min read

An includes template pastes its steps into your pipeline file. An extends template defines the outer structure and lets teams add steps only at points you allow. Microsoft's guidance says that for the most secure pipelines, start with extends templates, and anchor them to a branch or tag.

Two ways to reuse

Microsoft's documentation on templates for security describes two kinds. An includes template inserts the template's code directly into the file that references it, similar to an include in C++. An extends template defines the outer structure of the pipeline and exposes specific points for customization, closer to inheritance.

When you adopt a shared or public template, that difference decides how much control the consuming team keeps.

Side by side

PropertyIncludes templateExtends template
Who owns the outer structureThe consuming pipelineThe template
Can the team add arbitrary stepsYesOnly where parameters allow
Good forReusing a common step blockEnforcing a required shape
Security effectConvenienceHelps prevent malicious code infiltration, per Microsoft

What an extends template can enforce

Microsoft lists several built in protections you can use inside an extends template:

  • Step targets. Restrict specified steps to run in a container instead of on the host, so they cannot modify agent configuration or leave code behind for later runs. A container can also limit network access.
  • Type safe parameters. Parameters can enumerate allowed values, such as a fixed list of agent pools, rather than accepting any string.
  • Required steps. The template can include steps that always run, such as credential scanning.

Pin the template

The documentation's own tip is to anchor an extends template to a particular Git branch or tag, so breaking changes do not affect existing pipelines. Its example references a template repository at a tag. Treat that reference like a dependency version: choose it on purpose and change it through review.

Checks on protected resources

Microsoft says templates can help enforce checks on protected resources, which form the foundation of the security model for Azure Pipelines. Pairing an extends template with a required template check means a pipeline that does not extend your template cannot use the protected resource. See the required template check for the setup.

How to adopt a shared template safely

  1. Read it end to end, including every parameter.
  2. Check which steps run on the host and which run in containers.
  3. Pin the reference to a tag or branch you control.
  4. Decide which customization points teams really need and keep them few.
  5. Put the template repository behind pull requests and code owners.
  6. Test in a sandbox project before you require it.

Quick check

Does an extends template stop all misuse?

No. It limits where teams can add steps and what those steps can reach. It does not review the content of steps teams are allowed to add.

Should I convert every includes template to an extends template?

Not necessarily. Includes work fine for reusable step blocks. Use extends where you need to guarantee structure, such as production deploy pipelines.

Sources

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.