Extends

The extends keyword allows you to create a pipeline that inherits from and extends a template. This approach is powerful for standardizing pipelines across your organization while still providing flexibility for individual projects.

Schema Reference

extends: # Required. Extends a template.
  template: string # The template referenced by the pipeline to extend.
  parameters: # Parameters used in the extend.
pool: string | pool # Pool where jobs in this pipeline will run unless otherwise specified.
name: string # Pipeline run number.
appendCommitMessageToRunName: boolean # Append the commit message to the build number. The default is true.
trigger: none | trigger | [ string ] # Continuous integration triggers.
parameters: [ parameter ] # Pipeline template parameters.
pr: none | pr | [ string ] # Pull request triggers.
schedules: [ cron ] # Scheduled triggers.
resources: # Containers and repositories used in the build.
  builds: [ build ] # List of build resources referenced by the pipeline.
  containers: [ container ] # List of container images.
  pipelines: [ pipeline ] # List of pipeline resources.
  repositories: [ repository ] # List of repository resources.
  webhooks: [ webhook ] # List of webhooks.
  packages: [ package ] # List of package resources.
variables: variables | [ variable ] # Variables for this pipeline.
lockBehavior: string # Behavior lock requests from this stage should exhibit in relation to other exclusive lock requests.

Basic Example

Here's a basic example of a pipeline that extends a template:

Template Example

The template being extended (templates/main-pipeline-template.yml):

Advanced Examples

Extending Templates with Multiple Stages

Template with Conditional Stages

Using Extends with Repository Templates

Templates can be stored in different repositories and reused across multiple projects:

Best Practices for Template Extension

  1. Standardize Core Build Logic: Keep core build, test, and deployment logic in templates to ensure consistency across projects.

  2. Use Parameters for Flexibility: Design templates with parameters to accommodate different project requirements without modifying the template itself.

  3. Version Your Templates: Use tags or specific branch references when extending templates from a shared repository to ensure stability.

  4. Template Composition: Create specialized templates for different types of projects (e.g., web apps, APIs, libraries) that can extend more generic base templates.

  5. Document Template Parameters: Clearly document the required and optional parameters for each template to facilitate adoption.

  6. Include Validation: Add parameter validation in your templates to catch configuration errors early.

  7. Multi-stage Templates: Design templates that cover the entire CI/CD process, from build to deployment across multiple environments.

  8. Environment Specific Logic: Use conditionals to include environment-specific steps (e.g., additional security checks for production).

Template Extension Use Cases

  1. Standardized CI/CD Pipelines: Create organizational standards for different application types.

  2. Compliance Enforcement: Ensure all projects follow security and compliance requirements by embedding them in templates.

  3. Accelerating New Projects: Provide ready-to-use pipeline templates for new projects, reducing setup time.

  4. Multi-environment Deployment: Create templates that handle the complexity of deploying to multiple environments with appropriate approvals.

  5. Cross-platform Applications: Use templates with matrix strategies to build and test applications on multiple platforms.

Last updated