Use conditional logic in workflows
This guide shows how to branch a workflow with an if task, which runs one block or another depending on a condition.
Basic if task
Add an if key to a task entry to make it an if task:
name: Conditional example
compute_type: cpu-4
blocks:
main:
tasks:
classify:
name: Classify
route:
name: Route
start_on:
- classify
if:
condition: ${{tasks.classify.outputs.category == 'priority'}}
true: priority_block
false: standard_block
priority_block:
tasks:
urgent_action:
name: Urgent action
standard_block:
tasks:
normal_action:
name: Normal action
When classify completes, route evaluates the condition. If it is truthy, priority_block runs. Otherwise standard_block runs. Tasks in either block can read classify's outputs, because route waits on it.
Omit the false branch
When you omit false and the condition is falsy, the if task completes without entering a block, and the tasks that start_on it still run:
if:
condition: ${{inputs.send_notification == 'true'}}
true: notify_block
Branch on a run input
A condition can compare a run input with text. Inputs are text, so compare them with a quoted string:
if:
condition: ${{inputs.environment == 'production'}}
true: production_steps
false: staging_steps
The comparison ignores letter case, so Production takes the true branch too.
Check which branch ran
After starting a run, open it and find the if task in its Workflow Graph: the node names the branch the condition took, and expands to show the tasks of the block it entered. UI representation describes the node.