Conditions
Conditions can be used to limit pipeline step execution at runtime. For example, you may want to limit step execution by branch:
1 kind: pipeline
2 type: digitalocean
3 name: default
4
5 token:
6 from_secret: token
7
8 steps:
9 - name: build
10 commands:
11 - go build
12 - go test
13 when:
14 branch:
15 - master
16 - feature/*
You can use wildcard matching in your conditions. Note that conditions use glob pattern matching, not regular expressions.
13 when:
14 ref:
15 - refs/heads/master
16 - refs/heads/**
17 - refs/pull/*/head
You can also combine multiple conditions. Note that all conditions must evaluate to true when combining multiple conditions.
13 when:
14 branch:
15 - master
16 event:
17 - 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.
13 when:
14 branch:
15 - master
16 - feature/*
Example include syntax:
13 when:
14 branch:
15 include:
16 - master
17 - feature/*
Example exclude syntax:
13 when:
14 branch:
15 exclude:
16 - master
17 - 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.
13 when:
14 event:
15 - push
16 - pull_request
17 - tag
18 - promote
19 - rollback
Example include syntax:
13 when:
14 event:
15 include:
16 - push
17 - pull_request
Example exclude syntax:
13 when:
14 event:
15 exclude:
16 - 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.
13 when:
14 ref:
15 - refs/heads/feature-*
16 - refs/tags/*
Example include syntax:
13 when:
14 ref:
15 include:
16 - refs/heads/feature-*
17 - refs/pull/**
18 - refs/tags/**
Example exclude syntax:
13 when:
14 ref:
15 exclude:
16 - refs/heads/feature-*
17 - refs/pull/**
18 - refs/tags/**
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.
13 when:
14 repo:
15 - octocat/hello-world
Example include syntax:
13 when:
14 repo:
15 include:
16 - octocat/hello-world
17 - spacebhost/hello-world
Example exclude syntax:
13 when:
14 repo:
15 exclude:
16 - octocat/hello-world
17 - spacebhost/hello-world
Example using wildcard matching:
13 when:
14 repo:
15 include:
16 - 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.
13 when:
14 instance:
15 - drone.instance1.com
16 - drone.instance2.com
Example include syntax:
13 when:
14 instance:
15 include:
16 - drone.instance1.com
17 - drone.instance2.com
Example exclude syntax:
13 when:
14 instance:
15 exclude:
16 - drone.instance1.com
17 - drone.instance2.com
Example using wildcard matching:
13 when:
14 instance:
15 include:
16 - *.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.
13 when:
14 status:
15 - failure
Execute a step on failure:
13 when:
14 status:
15 - failure
Execute a step on success or failure:
13 when:
14 status:
15 - success
16 - failure
The following configuration is redundant. The default behavior is for pipeline steps to only execute when the pipeline is in a passing state.
13 when:
14 status:
15 - success
By Target
The target condition limits step execution based on the target deployment environment. This only applies to promotion and rollback events.
13 when:
14 target:
15 - production
Example include syntax:
13 when:
14 target:
15 include:
16 - staging
17 - production
Example exclude syntax:
13 when:
14 target:
15 exclude:
16 - production