Stages

Stages are a key organizational concept in Azure DevOps Pipelines that allow you to group jobs together and run them in a specific sequence. Each stage represents a logical boundary in your pipeline, such as build, test, and deploy, enabling you to implement practices like Continuous Integration (CI) and Continuous Deployment (CD).

Pipeline Schema for Stages

stages: [ stage | template ] # Required. Stages are groups of jobs that can run sequentially or in parallel.
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

Stage Schema

Basic Stage Example

Advanced Examples

Conditional Stages

Parallel and Sequential Stages

Stages with Approval Gates

Stages with Variables

Using Templates in Stages

Deployment Stages with Multiple Jobs

Best Practices for Using Stages

  1. Logical Grouping: Group related jobs into stages based on their purpose (build, test, deploy)

  2. Clear Naming: Use descriptive stage names that indicate their purpose

  3. Dependencies: Clearly define stage dependencies using the dependsOn property

  4. Conditions: Use conditions to control when stages should run

  5. Environments: For deployment stages, associate with environments to enable approvals and checks

  6. Templates: Extract reusable stage configurations into templates

  7. Variables: Scope variables to the stages where they are needed

Stage Lock Behavior

The lockBehavior property controls how a stage interacts with exclusive pipeline locks:

  • sequential: Wait for earlier requested exclusive locks (default)

  • runLatest: Run only the latest requested exclusive lock

Last updated