About Promotions
You can use the promotion feature to promote code to a target environment by build number, for example, promote build number 42 to production. Here are some of the benefits of using promotions:
- Create repeatable deployments
- Create an audit trail
- Reduce human error
- Segregation of duties
- Revoke developer access to server environments
How it Works
When you promote a build, Drone creates a new build (with a new build number) that inherits its values from the build being promoted. This new build will have an event type is set to promote. You can reference the event type and target environment in your pipeline configuration.
When Drone executes your build, by default, it executes all pipelines and all steps defined in your yaml. You can limit pipeline and step execution by event and by target environment.
- Limit pipeline execution by target environment:
1 kind: pipeline
2 type: docker
3 name: default
4
5 steps:
6 - name: test
7 image: node
8 commands:
9 - npm install
10 - npm run test
11 - npm run bundle
12
13 - name: deploy
14 image: plugins/ssh
15 settings: ...
16
17 trigger:
18 event:
19 - promote
20 target:
21 - production
- Limit pipeline step execution by target environment:
1 kind: pipeline
2 type: docker
3 name: deploy
4
5 steps:
6 - name: test
7 image: node
8 commands:
9 - npm install
10 - npm run test
11 - npm run bundle
12
13 - name: deploy
14 image: plugins/ssh
15 settings: ...
16 when:
17 event:
18 - promote
19 target:
20 - production
- Create separate pipelines for promotions:
1 kind: pipeline
2 type: docker
3 name: build
4
5 steps:
6 - name: test
7 image: node
8 commands:
9 - npm install
10 - npm run test
11
12 trigger:
13 event:
14 - push
15 - pull_request
16
17 ---
18 kind: pipeline
19 type: docker
20 name: deploy
21
22 steps:
23 - name: test
24 image: node
25 commands:
26 - npm install
27 - npm run test
28 - npm run bundle
29
30 - name: deploy
31 image: plugins/ssh
32 settings: ...
33
34 trigger:
35 event:
36 - promote
37 target:
37 - production
How To Promote
You can promote builds using the command line utility:
- Use the build promote command
$ drone build promote <repo> <number> <environment>
- Example promotes build number 42 to staging:
$ drone build promote octocat/hello-world 42 staging
- Example promotes build number 42 to production:
$ drone build promote octocat/hello-world 42 production
In the above examples we reference staging and production environments, however, the environment is a freeform field. You can use any environment name.
Further Reading