Skip to content

Commit 5529417

Browse files
authored
Update configuration-reference.md
Added API v2 'When" content to Workflows section of page
1 parent 2972aea commit 5529417

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

jekyll/_cci2/configuration-reference.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,6 +1201,50 @@ ignore | N | String, or List of Strings | Either a single tag specifier, or a li
12011201

12021202
For more information, see the [Executing Workflows For a Git Tag]({{ site.baseurl }}/2.0/workflows/#executing-workflows-for-a-git-tag) section of the Workflows document.
12031203

1204+
##### **`when` in Workflows**
1205+
1206+
## Using 'when' in Workflows
1207+
1208+
When using CircleCI API v2, you may use a `when` clause (the inverse clause is also supported) under a workflow declaration with a boolean value to determine whether or not to run that workflow. The most common use of `when` in API v2 is to use a pipeline parameter as the value, allowing an API trigger to pass that parameter to determine which workflows to run.
1209+
1210+
The example below shows an example configuration using two different pipeline parameters. You may use one of the parameters to drive whether a particular workflow, while you may use the other parameter determines whether a particular step will run.
1211+
1212+
```yaml
1213+
version: 2.1
1214+
1215+
parameters:
1216+
run_integration_tests:
1217+
type: boolean
1218+
default: false
1219+
deploy:
1220+
type: boolean
1221+
default: false
1222+
1223+
workflows:
1224+
version: 2
1225+
integration_tests:
1226+
when: << pipeline.parameters.run_integration_tests >>
1227+
jobs:
1228+
- mytestjob
1229+
- when:
1230+
condition: << pipeline.parameters.deploy >>
1231+
steps:
1232+
- deploy
1233+
1234+
jobs:
1235+
...
1236+
```
1237+
1238+
This example prevents the workflow `integration_tests` from being triggered unless the tests were invoked explicitly when the pipeline is triggered with the following in the `POST` body:
1239+
1240+
```
1241+
{
1242+
"parameters": {
1243+
"run_integration_tests": true
1244+
}
1245+
}
1246+
```
1247+
12041248
###### *Example*
12051249

12061250
```

0 commit comments

Comments
 (0)