Conditional execution
Skip a stage or step at runtime by setting a condition that must evaluate to true for it to run.
Conditional execution lets you skip a stage or step based on a condition evaluated at runtime. If the condition evaluates to false, Harness skips it and marks it as not executed; execution continues from the next stage or step.
Use conditional execution to:
Run a deploy stage only when the pipeline has succeeded up to that point
Always run a cleanup stage regardless of prior failures
Skip a stage when a pipeline input does not match a target value
What you will learn
How to skip a stage or step at runtime using the
ifkey and a JEXL conditionWhat the built-in base conditions (
OnPipelineSuccess,OnPipelineFailure,Always) doHow to combine conditions and gate execution on a pipeline input value
How skipped stages behave and what happens to their outputs
YAML
Use the if key on a stage or step. The condition is a JEXL expression:
stages:
- name: deploy-prod
id: deploy_prod
if: <+OnPipelineSuccess>
steps:
- name: deploy
id: deploy
run:
script: ./deploy-prod.shIf the expression resolves to false, the stage is skipped entirely. No steps run, and no failure is recorded.
Base execution conditions
These built-in JEXL conditions control when a stage runs relative to the pipeline state:
<+OnPipelineSuccess>
All previous stages succeeded (default behavior)
<+OnPipelineFailure>
At least one previous stage failed
<+Always>
Always runs, regardless of prior stage status
Combine with an expression
You can combine a base condition with an additional JEXL expression using &&:
To gate on a pipeline input value, wrap the input expression in single quotes so the resolved value becomes a JEXL string literal:
Behavior
A skipped stage does not count as a failure.
Downstream stages that depend on a skipped stage's outputs will receive empty values for those outputs.
Conditional execution is evaluated before the stage starts; it cannot be based on that stage's own steps.
Next steps
Go to On failure to control what happens when a stage fails.
Go to Stage inputs & outputs to reference stage outputs in conditions.
Go to Pipelines overview to review the pipeline model.
Last updated
Was this helpful?