Skip to main content

Stage and step conditional execution settings

This topic describes pipeline stage and step Conditional Execution settings.

Failure strategy takes precedence over conditional execution

Harness pipeline stages and steps both include Conditional Execution and Failure Strategy settings:

Using these settings together in multiple stages requires some consideration.

Let's say you have a pipeline with two stages: stage 1 followed by stage 2.

Stage 2's Conditional Execution is set to Execute this step only if the prior stage or step failed. Stage 1's Failure Strategy is set to Rollback Stage on All Errors.

If stage 1 has any error it is rolled back and so it is not considered a failure. Hence, stage 2's Conditional Execution is not executed.

In order to get stage 2 to execute, you can set the stage 1 Failure Strategy to Ignore Failure. Rollback will not occur and stage 2's Conditional Execution is executed.

To ensure a step executes even if the rollback fails, include it in the Rollback stage, configure Conditional Execution to Always execute this stage for your step, and then set the previous step's Failure Strategy to Mark as failure for all errors. Because we wouldn't usually want the rollback to continue when there are errors, you must make these two changes to ensure the execution.

Stage and step priority

The stage conditional execution applies to all steps that do not have their own conditional execution. A step's conditional execution overrides its stage's conditional execution.

Stage conditions

Execute this stage if pipeline execution is successful so far

Select this option if you only want this stage to run when all previous stages were successful.

This is the default setting and used most of the time.

Always execute this stage

Select this option if you always want this stage to run regardless of the success or failure of previous stages.

Execute this stage only if prior pipeline or stage failed

Select this option if you always want this stage to run only if the prior Pipeline or stage failed.

And execute this stage only if the following JEXL condition evaluates to true

Only execute this stage is a JEXL expression is met (evaluates to true).

In the JEXL expression, you could use any of the Pipeline variables, including the output of any previous steps.

Examples:

  • <+pipeline.stages.cond.spec.execution.steps.echo.status> == "SUCCEEDED"
  • <+environment.name> != “QA”

For more information on variable expressions, go to built-in custom Harness variables reference.

Step conditions

Execute this step if the stage execution is successful thus far

Select this option if you only want this step to run when all previous steps were successful.

This is the default setting and used most of the time.

Always execute this step

Select this option if you always want this step to run regardless of the success or failure of previous steps.

Execute this step only if prior stage or step failed

Select this option if you always want this step to run only if the prior stage or step failed.

And execute this step only if the following JEXL condition evaluates to true

Only execute this step if a JEXL expression is met (evaluates to true).

In the JEXL expression, you could use any of the Pipeline variables, including the output of any previous steps.

Example:

  • <+pipeline.stages.cond.spec.execution.steps.echo.status> == "SUCCEEDED"
  • <+environment.name> != “QA”

For more information on variable expressions, go to built-in and custom Harness variables reference.

Variable expressions in conditional execution settings

Stages and steps support variable expressions in the JEXL conditions of their Conditional Execution settings.

You can only use variable expressions in the JEXL conditions that can be resolved before the stage.

Since Conditional Execution settings are used to determine if the stage should be run, you cannot use variable expressions that can't be resolved until the stage is run.

Deployment status

Deployment status values are a Java enum. The list of values can be seen in the deployments Status filter:

You can use any status value in a JEXL condition. For example, <+pipeline.stages.cond.spec.execution.steps.echo.status> == "FAILED".