Skip to content

Commit 31be791

Browse files
authored
Merge pull request circleci#908 from circleci/eric-hu-patch-1
Add a recursive, multi-job example
2 parents 020b11b + c2ee9d5 commit 31be791

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

jekyll/_cci2/defining-multiple-jobs.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,49 @@ A few notes about this example:
5353

5454
- `CIRCLE_API_TOKEN` should be the API token from your project's setting page.
5555
- `<vcs-type>/<org>/<repo>` should be replaced with your own VCS and org/repo names; at time of writing, `<vcs-types>` must be either `github` or `bitbucket`.
56+
57+
## Conditionally triggering jobs
58+
59+
Building on the previous example, suppose you want to build docker images with `setup_remote_docker` only for builds that should be deployed. You can use a config such as the following:
60+
61+
```YAML
62+
build:
63+
docker:
64+
- image: ruby:2.4.0
65+
environment:
66+
- LANG: C.UTF-8
67+
working_directory: /my-project
68+
parallelism: 2
69+
steps:
70+
- checkout
71+
72+
- run:
73+
name: Tests
74+
command: |
75+
echo "run some tests"
76+
77+
- deploy:
78+
name: conditionally run a deploy job
79+
command: |
80+
# replace this with your build/deploy check (i.e. current branch is "release")
81+
if [[ true ]]; then
82+
curl --user ${CIRCLE_API_TOKEN}: \
83+
--data build_parameters[CIRCLE_JOB]=deploy_docker \
84+
--data revision=$CIRCLE_SHA1 \
85+
https://circleci.com/api/v1.1/project/github/$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME/tree/$CIRCLE_BRANCH
86+
fi
87+
88+
deploy_docker:
89+
docker:
90+
- image: ruby:2.4.0
91+
working_directory: /
92+
steps:
93+
- setup_remote_docker
94+
- run: echo "deploy section running"
95+
```
96+
97+
**Notes on the above example:**
98+
99+
- Using the `deploy` step in the build job is important so that you don't trigger N builds, where N is your parallelism level.
100+
- We use an API call with `build_parameters[CIRCLE_JOB]=deploy_docker` so that only the `deploy_docker` job will be run.
101+
- **This approach is a temporary workaround for the current features available during Beta.** Soon we'll be adding a much more elegant way to manage multiple jobs.

0 commit comments

Comments
 (0)