WhenExpression
Defines a condition that must be true for a task to execute.The value to evaluate.Can be a static string or reference parameters/results:
$(params.paramName)$(tasks.taskName.results.resultName)- Static value:
"production"
The comparison operator.Values:
in- Input must match one of the valuesnotin- Input must not match any of the values
Array of values to compare against.Must have at least one value.
Common Expression Language (CEL) expression for advanced conditions.Alpha feature requiring feature flag.Example:
"'$(params.env)' == 'prod' && '$(tasks.test.results.status)' == 'passed'"Evaluation
All when expressions on a task must evaluate totrue for the task to execute:
- If all expressions are true: Task executes
- If any expression is false: Task is skipped
Examples
Simple String Comparison
Check Multiple Conditions
Based on Previous Task Result
Notin Operator
Multiple Values
Using Array Results
CEL Expressions (Alpha)
When Expressions in Finally Tasks
Finally tasks support when expressions to control their execution:Aggregate Status
Check the overall status of pipeline tasks:Common Patterns
Deploy Based on Branch
Run Tests Conditionally
Feature Flag Gating
Environment-Specific Tasks
Skipped Tasks in Status
When a task is skipped due to when expressions, it appears in the PipelineRun status:Best Practices
- Keep expressions simple - Complex logic is harder to debug
- Use meaningful parameter names - Make conditions self-documenting
- Combine with runAfter - Ensure dependencies are met before checking conditions
- Document conditional logic - Explain why tasks are conditional
- Test both paths - Verify tasks execute and skip as expected
- Use notin for exclusions - More readable than negative checks
- Validate result references - Ensure referenced tasks produce results
- Consider finally tasks - For cleanup that should always run
Limitations
- All when expressions use AND logic (all must be true)
- No built-in OR operator (use multiple tasks or CEL for OR logic)
- Cannot reference results from tasks that haven’t run
- Values must be strings (numeric comparisons require CEL)
- No built-in regex matching (use CEL for pattern matching)