Overview
Users can conditionally trigger a workflow or steps using Advanced Logic in their config.yml
file.
Specific logic statements can be used to create multiple nested conditions that will always, at the top level, result in true
or false
-- which in turn determines if the workflow or steps are triggered.
Logic statements are evaluated to boolean values at configuration compilation time, that is, before the workflow is run.
Example config with conditional steps:
- when:
condition:
or:
- and:
- equal: [ main, << pipeline.git.branch >> ]
- or: [ << pipeline.parameters.param1 >>, << pipeline.parameters.param2 >> ]
- or:
- equal: [ false, << pipeline.parameters.param1 >> ]
steps:
- run: echo "I am on main AND param1 is true OR param2 is true -- OR param1 is false"
Example config with a conditional workflow:
workflows:
conditional-workflow:
when:
and: # All must be true to trigger
- equal: [ main, << pipeline.git.branch >> ]
- not: << pipeline.parameters.param1 >>
- or: [ << pipeline.parameters.param1 >>, << pipeline.parameters.param2 >> ]
jobs:
- job-on-condition
Nested Conditional Logic statements:
Conditions can be nested in an arbitrary fashion, according to their argument specifications, and to a maximum depth of 100 levels. This allows for some complex logic, as an example of multiple nested conditions:
- when:
condition:
or:
- and:
- or:
- and:
- equal: [ main, << pipeline.git.branch >> ]
- equal: [ false, << pipeline.parameters.param1 >> ]
- or:
- not: << pipeline.parameters.param3 >>
- or:
- equal: [ false, << pipeline.parameters.param3 >> ]
- or: [ << pipeline.parameters.param1 >>, << pipeline.parameters.param2 >> ]
- or:
- equal: [ true, << pipeline.parameters.param4 >> ]
steps:
- run: echo "param 4 is true OR the other nested conditions are true"
Comments
Article is closed for comments.