Version 0.9.0
Language EN

Conditions

Conditions can be used to limit pipeline step execution at runtime. For example, you may want to limit step execution by branch:

kind: pipeline
name: default

steps:
- name: build
  image: golang
  commands:
  - go build
  - go test
  when:
    branch:
    - master
    - feature/*

You can combine multiple conditions. The build step is only executed when the branch is master and the event is push:

kind: pipeline
name: default

steps:
- name: build
  image: golang
  commands:
  - go build
  - go test
  when:
    branch:
    - master
    event:
    - push

By Branch

The branch condition limits step execution based on the git branch. Please note that the target branch is evaluated for pull requests; and branch names are not available for tag events.

kind: pipeline
name: default

steps:
- name: build
  image: golang
  commands:
  - go build
  - go test
  when:
    branch:
    - master
    - feature/*

Example include syntax:

when:
  branch:
    include:
    - master
    - feature/*

Example exclude syntax:

when:
  branch:
    exclude:
    - master
    - feature/*

By Event

The event condition limits step execution based on the drone event type. This can be helpful when you want to limit steps based on push, pull request, tag and more.

kind: pipeline
name: default

steps:
- name: build
  image: golang
  commands:
  - go build
  - go test
  when:
    event:
    - push
    - pull_request
    - tag
    - promote
    - rollback

Example include syntax:

when:
  event:
    include:
    - push
    - pull_request

Example exclude syntax:

when:
  event:
    exclude:
    - pull_request

By Reference

The reference condition limits step execution based on the git reference name. This can be helpful when you want to glob match branch or tag names.

kind: pipeline
name: default

steps:
- name: build
  image: golang
  commands:
  - go build
  - go test
  when:
    ref:
    - refs/heads/feature-*
    - refs/tags/v1.*

Example include syntax:

when:
  ref:
    include:
    - refs/heads/feature-*
    - refs/tags/v1.*

Example exclude syntax:

when:
  ref:
    exclude:
    - refs/heads/feature-*
    - refs/tags/v1.*

By Repository

The repository condition limits step execution based on repository name. This can be useful when Drone is enabled for a repository and its forks, and you want to limit execution accordingly.

kind: pipeline
name: default

steps:
- name: build
  image: golang
  commands:
  - go build
  - go test
  when:
    repo:
    - octocat/hello-world

Example include syntax:

when:
  instance:
    include:
    - octocat/hello-world
    - spacebhost/hello-world

Example exclude syntax:

when:
  repo:
    exclude:
    - octocat/hello-world
    - spacebhost/hello-world

Example using wildcard matching:

when:
  repo:
    include:
    - octocat/*

By Instance

The instance condition limits step execution based on the Drone instance hostname. This can be useful if you have multiple Drone instances configured for a single repository, sharing the same yaml file, and want to limit steps by instance.

kind: pipeline
name: default

steps:
- name: build
  image: golang
  commands:
  - go build
  - go test
  when:
    instance:
    - drone.instance1.com
    - drone.instance2.com

Example include syntax:

when:
  instance:
    include:
    - drone.instance1.com
    - drone.instance2.com

Example exclude syntax:

when:
  instance:
    exclude:
    - drone.instance1.com
    - drone.instance2.com

Example using wildcard matching:

when:
  instance:
    include:
    - *.company.com

By Status

The status condition limits step execution based on the pipeline status. For example, you may want to configure Slack notification only on failure.

kind: pipeline
name: default

steps:
- name: build
  image: golang
  commands:
  - go build
  - go test

- name: notify
  image: plugins/slack
  when:
    status:
    - failure

Execute a step on failure:

when:
  status:
  - failure

Execute a step on success or failure:

when:
  status:
  - success
  - failure

The following configuration is redundant. The default behavior is for pipeline steps to only execute when the pipeline is in a passing state.

when:
  status:
  - success

By Target

The target condition limits step execution based on the target deployment environment. This only applies to promotion and rollback events.

kind: pipeline
name: default

steps:
- name: build
  image: golang
  commands:
  - go build
  - go test

- name: publish
  image: plugins/scp
  when:
    target:
    - production

On This Page:

Getting Help

Enterprise Support
Real-time chat support from the developers that wrote the code.
Mailing List
Search for information in the mailing list archives, or post a question.