How to limit build concurrency per project


#1

IMPORTANT: this does not work with the experimental Kubernetes runtime

In some cases you may want to prevent a repository from running multiple builds at the same time, or you may even want to prevent certain branches or events from executing at the same time. An example use case may be that you need to ensure two deployments to production are not triggered at the same time.

You can set concurrency limits (below) to limit the number of named pipelines that can execute at the same time. You will see we name the pipeline “deploy” and we limit concurrency to “1”. This will instruct Drone to only execute 1 pipeline named “deploy” at a time.

kind: pipeline
name: deploy

concurrency:
  limit: 1

steps: ...

In some cases you may want to limit concurrency based on event or branch. We can do this by defining multiple pipelines in our yaml. In the below example, the first pipeline that we define limits tag events to a single concurrent build. The second pipeline will execute push and pull_request events with no concurrency limits (unbounded).

---
kind: pipeline
name: tag

concurrency:
  limit: 1

steps: ...

trigger:
  event: [ tag ]

---
kind: pipeline
name: default

steps: ...

trigger:
  event: [ pull_request, push ]