Skip to main content
When expressions enable conditional execution of PipelineTasks based on runtime values.

WhenExpression

Defines a condition that must be true for a task to execute.
string
The value to evaluate.Can be a static string or reference parameters/results:
  • $(params.paramName)
  • $(tasks.taskName.results.resultName)
  • Static value: "production"
string
required
The comparison operator.Values:
  • in - Input must match one of the values
  • notin - Input must not match any of the values
[]string
required
Array of values to compare against.Must have at least one value.
string
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 to true 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)

CEL expressions are an alpha feature and require the appropriate feature flag.

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

  1. Keep expressions simple - Complex logic is harder to debug
  2. Use meaningful parameter names - Make conditions self-documenting
  3. Combine with runAfter - Ensure dependencies are met before checking conditions
  4. Document conditional logic - Explain why tasks are conditional
  5. Test both paths - Verify tasks execute and skip as expected
  6. Use notin for exclusions - More readable than negative checks
  7. Validate result references - Ensure referenced tasks produce results
  8. Consider finally tasks - For cleanup that should always run

Limitations

  1. All when expressions use AND logic (all must be true)
  2. No built-in OR operator (use multiple tasks or CEL for OR logic)
  3. Cannot reference results from tasks that haven’t run
  4. Values must be strings (numeric comparisons require CEL)
  5. No built-in regex matching (use CEL for pattern matching)