Conditions

Note: Conditions are deprecated, use WhenExpressions instead.

Overview

A Condition resource in Tekton allows you to conditionalize the execution of Tasks within a Pipeline. You define each Condition within your PipelineRun definition and then conditionalize each desired Task in the corresponding Pipeline definition.

The Condition resource runs its own container image that executes the logic that evaluates your chosen condition. This container runs to completion and must return an exit code value of 0 for the check to be successful; otherwise the conditionalized Task as well as its Task dependencies (defined via runAfter) and Resource dependencies (such as results) do not execute.

Note: Labels and annotations specified in the Condition's metadata are automatically propagated to the Pod.

Configuring a Condition

A Condition definition supports the following fields:

  • Required:
    • apiVersion - Specifies the API version, for example tekton.dev/v1alpha1.
    • kind - Identifies this resource object as a Condition object.
    • metadata - Specifies metadata that uniquely identifies this Condition object. For example, a name.
    • spec - Specifies the configuration information for this Condition resource object. This must include:
    • check - Specifies a container that you want to run for evaluating this Condition.
    • description - Provides a meaningful description of this Condition object.

Specifying the condition check

The check field (required) specifies a single piece of evaluation logic that you want to run before the corresponding Task in your Pipeline can execute. This field must specify a Step.

Specifying Parameters

You can specify parameters to pass to the Condition's evaluation logic at run time. Sub-fields within the check field can access these parameter values using Tekton’s templating syntax as follows:

spec:
  parameters:
    - name: image
      default: ubuntu
  check:
    image: $(params.image)

Parameter names: - Must only contain alphanumeric characters, hyphens (-), and underscores (_). - Must begin with a letter or an underscore (_).

For example, fooIs-Bar_ is a valid parameter name, but barIsBa$ or 0banana are not.

Each declared parameter has a type field, which can be set to either array or string, and defaults to string if you don’t specify a value. The description and default fields for a Parameter are optional. The array type is useful in situations such as checking that a pushed branch name doesn’t collide with any of the specified protected branch names.

Specifying Resources

You can specify input PipelineResources in your Condition definition to provide the Condition's container step with data or context necessary to run the evaluation logic.

Resources in Conditions behave the same way as in Tasks: - You can access them via variable substitution. - You can use the targetPath field to specify a mount point.

Adding a description

The description field (optional) allows you to specify a meaningful description for your Condition.

Code examples

For a better understanding of Conditions, study our code examples.


Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License.


Last modified January 1, 0001