Azure - Run 1 instance of your pipeline at a time

By xngo on October 26, 2022

A way to run multiple instances of your pipeline sequentially is to associate your pipeline to an environment and then assign an exclusive lock to that environement. When multiple instances of your pipeline are triggered, only the first one is running. Whereas the other instances are queued and in waiting mode. However, those instances that are waiting for too long will be canceled automatically.

  1. From Pipelines > Environments, create an empty environment.
    • Azure - Pipelines - Environment - create Azure - Pipelines - Environment - create empty
  2. From the newly created environment, open Approvals and checks
    • Azure - Pipelines - Environment - Approval n checks
  3. Add Exclusive Lock.
    • Azure - Pipelines - Environment - Approval n checks - Exclusive lock"
  4. In your YAML pipeline file(e.g. azure-pipelines.yaml), add deployment and environment as follows:
...
stages:
- stage: LoadTesting
  displayName: Load Testing
  jobs:
  - deployment: LoadTestingTmpLock
    environment: load-testing-lock-environment
  - job: LoadTesting
    displayName: Load Testing
...

About the author

Xuan Ngo is the founder of OpenWritings.net. He currently lives in Montreal, Canada. He loves to write about programming and open source subjects.