stages.template definition

You can define a set of stages in one file and use it multiple times in other files.

stages:
- template: string # Required as first property. Reference to a template for this stage.
  parameters: # Parameters used in a stage template.

Definitions that reference this definition: stages

Properties

template string. Required as first property.
Reference to a template for this stage.

parameters template parameters.
Parameters used in a stage template.

Remarks

Reference the stage template in the main pipeline.

- template: string # name of template to include
  parameters: { string: any } # provided parameters

Define the stages in the template.

parameters: { string: any } # expected parameters
stages: [ stage ]

Examples

In this example, a stage is repeated twice for two different testing regimes. The stage itself is specified only once.

# File: stages/test.yml

parameters:
  name: ''
  testFile: ''

stages:
- stage: Test_${{ parameters.name }}
  jobs:
  - job: ${{ parameters.name }}_Windows
    pool:
      vmImage: windows-latest
    steps:
    - script: npm install
    - script: npm test -- --file=${{ parameters.testFile }}
  - job: ${{ parameters.name }}_Mac
    pool:
      vmImage: macos-latest
    steps:
    - script: npm install
    - script: npm test -- --file=${{ parameters.testFile }}
# File: azure-pipelines.yml

stages:
- template: stages/test.yml  # Template reference
  parameters:
    name: Mini
    testFile: tests/miniSuite.js

- template: stages/test.yml  # Template reference
  parameters:
    name: Full
    testFile: tests/fullSuite.js

See also