You can have the output of a task in your pipeline determine whether the pipeline runs or stops based on a condition that you supply. To pass or fail the pipeline based on the task output, you use the Condition task.

You use the Condition task as a decision point in your pipeline. By using the Condition task with a condition expression that you provide, you can evaluate any properties in your pipeline, stages, and tasks.

The result of the Condition task determines whether the next task in the pipeline runs.

  • A true condition allows the pipeline run continue.
  • A false condition stops the pipeline.

For examples of how to use the output value of one task as the input to the next task by binding the tasks together with a Condition task, see How do I use variable bindings in Automation Pipelines pipelines.

Table 1. How the Condition task and its condition expression relate to the pipeline
Condition task What it affects What it does

Condition task

Pipeline

The Condition task determines whether the pipeline runs or stops at that point, based on whether the task output is true or false.

Condition expression

Condition task output

When the pipeline runs, the condition expression that you include in the Condition task produces a true or false output status. For example, a condition expression can require the Condition task output status as Completed, or use a build number of 74.

The condition expression appears on the Task tab in the Condition task.

The supported constructs for the conditional expression appear and provide examples for pipeline variables, task output variables, values, and operators.

The Condition task differs in function and behavior from the On Condition setting in other types of tasks.

The On Condition setting is available in other types of tasks.

In other types of tasks, the On Condition determines whether the current task runs, rather than successive tasks, based on the evaluation of its precondition expression of true or false. The condition expression for the On Condition setting produces a true or false output status for the current task when the pipeline runs. The On Condition setting appears on the Task tab with its own condition expression.

This example uses the Condition task.

Prerequisites

  • Verify that a pipeline exists, and that it includes stages and tasks.

Procedure

  1. In your pipeline, determine the decision point where the Condition task must appear.
  2. Add the Condition task before the task that depends on its status of pass or fail.
  3. Add a condition expression to the Condition task.
    For example: "${Stage1.task1.output.status}" == "COMPLETED" || ${input.buildNumber} == 74
    Add a Condition task with a condition expression that evaluates as true or false when the pipeline runs.
  4. Validate the task.
  5. Save the pipeline, then enable and run it.

Results

Watch the pipeline executions and notice whether the pipeline continues running, or stops at the Condition task.

What to do next

If you roll back a pipeline deployment, you can also use the Condition task. For example, in a rollback pipeline, the Condition task helps Automation Pipelines mark a pipeline failure based on the condition expression, and can trigger a single rollback flow for various failure types.

To roll back a deployment, see How do I roll back my deployment in Automation Pipelines.