Conditions
Note: Conditions are deprecated, use when expressions 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 exampletekton.dev/v1alpha1.kind- Identifies this resource object as aConditionobject.metadata- Specifies metadata that uniquely identifies thisConditionobject. For example, aname.spec- Specifies the configuration information for thisConditionresource object. This must include:check- Specifies a container that you want to run for evaluating thisCondition.description- Provides a meaningful description of thisConditionobject.
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
⚠️
PipelineResourcesare deprecated.Consider using replacement features instead. Read more in documentation and TEP-0074.
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
targetPathfield 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.
Feedback
Was this page helpful?
Thanks! Tell us how we can further improve.
Sorry about that. Tell us how we can further improve.