Triggers

Updated 2 years ago by Admin

When you push code to your repository, open a pull request, or create a tag, your source control management system automatically sends a webhook to Drone which in turn triggers pipeline execution. Use the triggers section to limit pipeline execution.

Example limits pipeline execution by branch:

1  kind: pipeline
2 type: exec
3 name: default
4
5 steps:
6 - name: build
7 commands:
8 - go build
9 - go test
10
11 trigger:
12 branch:
13 - master

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

11 trigger:
12 ref:
13 - refs/heads/master
14 - refs/heads/**
15 - refs/pull/*/head

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

11 trigger:
12 branch:
13 - master
14 event:
15 - push

By Branch

The branch trigger 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 triggers with tags. A tag is not associated with the source branch from which it was created.
11 trigger:
12 branch:
13 - master
14 - feature/*

Example include syntax:

11 trigger:
12 branch:
13 include:
14 - master
15 - feature/*

Example exclude syntax:

11 trigger:
12 branch:
13 exclude:
14 - master
15 - feature/*

By Event

The event trigger 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 triggers with tag events. A tag is not associated with the source branch from which it was created.
11 trigger:
12 event:
13 - push
14 - pull_request
15 - tag
16 - promote
17 - rollback

Example include syntax:

11 trigger:
12 event:
13 include:
14 - push
15 - pull_request

Example exclude syntax:

11 trigger:
12 event:
13 exclude:
14 - pull_request

By Reference

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

11 trigger:
12 ref:
13 - refs/heads/feature-*
14 - refs/tags/*

Example include syntax:

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

Example exclude syntax:

11 trigger:
12 ref:
13 exclude:
14 - refs/heads/feature-*
15 - refs/pull/**
16 - refs/tags/**

By Repository

The repository trigger 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.

11 trigger:
12 repo:
13 - octocat/hello-world

Example include syntax:

11 trigger:
12 repo:
13 include:
14 - octocat/hello-world
15 - spacebhost/hello-world

Example exclude syntax:

11 trigger:
12 repo:
13 exclude:
14 - octocat/hello-world
15 - spacebhost/hello-world

Example using wildcard matching:

11 trigger:
12 repo:
13 include:
14 - octocat/*


By Instance

The instance trigger 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.

11 trigger:
12 instance:
13 - drone.instance1.com
14 - drone.instance2.com

Example include syntax:

11 trigger:
12 instance:
13 include:
14 - drone.instance1.com
15 - drone.instance2.com

Example exclude syntax:

11 trigger:
12 instance:
13 exclude:
14 - drone.instance1.com
15 - drone.instance2.com

Example using wildcard matching:

11 trigger:
12 instance:
13 include:
14 - *.company.com


By Status

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

11 trigger:
12 status:
13 - failure

Execute a step on failure:

11 trigger:
12 status:
13 - failure

Execute a step on success or failure:

11 trigger:
12 status:
13 - success
14 - failure

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

11 trigger:
12 status:
13 - success


By Target

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

11 trigger:
12 target:
13 - production

Example include syntax:

11 trigger:
12 target:
13 include:
14 - staging
15 - production

Example exclude syntax:

11 trigger:
12 target:
13 exclude:
14 - production


How did we do?