Drone CI 中文文档

Conditions

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
kind: pipeline
type: exec
name: default

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

You can use wildcard matching in your conditions. Note that conditions use glob pattern matching, not regular expressions.

10
11
12
13
14
when:
  ref:
  - refs/heads/master
  - refs/heads/**
  - refs/pull/*/head

You can also combine multiple conditions. Note that all conditions must evaluate to true when combining multiple conditions.

10
11
12
13
14
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.

Note that you cannot use branch conditions with tags. A tag is not associated with the source branch from which it was created.
10
11
12
13
when:
  branch:
  - master
  - feature/*

Example include syntax:

10
11
12
13
14
when:
  branch:
    include:
    - master
    - feature/*

Example exclude syntax:

10
11
12
13
14
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.

Note that you cannot use branch conditions with tag events. A tag is not associated with the source branch from which it was created.
10
11
12
13
14
15
16
when:
  event:
  - push
  - pull_request
  - tag
  - promote
  - rollback

Example include syntax:

10
11
12
13
14
when:
  event:
    include:
    - push
    - pull_request

Example exclude syntax:

10
11
12
13
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.

10
11
12
13
when:
  ref:
  - refs/heads/feature-*
  - refs/tags/*

Example include syntax:

10
11
12
13
14
15
when:
  ref:
    include:
    - refs/heads/feature-*
    - refs/pull/**
    - refs/tags/**

Example exclude syntax:

10
11
12
13
14
15
when:
  ref:
    exclude:
    - refs/heads/feature-*
    - refs/pull/**
    - 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.

10
11
12
when:
  repo:
  - octocat/hello-world

Example include syntax:

10
11
12
13
14
when:
  repo:
    include:
    - octocat/hello-world
    - spacebhost/hello-world

Example exclude syntax:

10
11
12
13
14
when:
  repo:
    exclude:
    - octocat/hello-world
    - spacebhost/hello-world

Example using wildcard matching:

10
11
12
13
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.

10
11
12
13
when:
  instance:
  - drone.instance1.com
  - drone.instance2.com

Example include syntax:

10
11
12
13
14
when:
  instance:
    include:
    - drone.instance1.com
    - drone.instance2.com

Example exclude syntax:

10
11
12
13
14
when:
  instance:
    exclude:
    - drone.instance1.com
    - drone.instance2.com

Example using wildcard matching:

10
11
12
13
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.

10
11
12
when:
  status:
  - failure

Execute a step on failure:

10
11
12
when:
  status:
  - failure

Execute a step on success or failure:

10
11
12
13
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.

10
11
12
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.

10
11
12
when:
  target:
  - production

Example include syntax:

10
11
12
13
14
when:
  target:
    include:
    - staging
    - production

Example exclude syntax:

10
11
12
13
when:
  target:
    exclude:
    - production