Conditional expression allows a task or step that only runs if the condition is met. It can be defined on a task or on a step.
A conditional task consists of steps with a key
when. The purpose of the
when steps is customizing commands and job configuration to run on custom conditions (determined at compile time) that are checked before a workflow runs.
tasks: build-image: steps: ... when: branch == 'master'
A conditional step consists a step with a key
if. The step will only run if the expression evaluates to true.
tasks: build-image: steps: - checkout - run: sudo apt-get update ... - docker/build: image: example.com/demo if: branch == 'master'
The expression has access to the workflow related context objects
event. It can contain following tokens -
branch- refers to the git branch
tag- refers to the git tag if present
event- refer to the trigger event. Should be one of
platform- refers to the target operating system and architecture. for example
$GOARCHfor the possible values here.
You can provide more complex expression using operators and modifiers
branch == 'master' branch in ('master', 'staging') || branch =~ 'hotfix' || tag event == 'deployment' platform == 'linux/amd64'