Skip to main content
A Task is a collection of Steps that you define and arrange in a specific order of execution as part of your continuous integration flow. A Task executes as a Pod on your Kubernetes cluster.

Overview

A Task is available within a specific namespace, while a cluster resolver can be used to access Tasks across the entire cluster.
The cluster resolver is the recommended way to access Tasks across the cluster. ClusterTasks are deprecated.
A Task declaration includes the following elements:

Task Configuration

A Task definition supports the following fields:

Required Fields

string
required
Specifies the API version. For example, tekton.dev/v1 or tekton.dev/v1beta1.
string
required
Identifies this resource object as a Task object.
object
required
Specifies metadata that uniquely identifies the Task resource object. For example, a name.
object
required
Specifies the configuration information for this Task resource object.
array
required
Specifies one or more container images to run in the Task.

Optional Fields

string
An informative description of the Task.
array
Specifies execution parameters for the Task.
array
Specifies paths to volumes required by the Task.
array
Specifies the names under which Tasks write execution results.
array
Specifies one or more volumes that will be available to the Steps in the Task.
object
Specifies a Container step definition to use as the basis for all Steps in the Task.
array
Specifies Sidecar containers to run alongside the Steps in the Task.

Example Task Definition

Steps

A Step is a reference to a container image that executes a specific tool on a specific input and produces a specific output. To add Steps to a Task you define a steps field containing a list of desired Steps. The order in which the Steps appear in this list is the order in which they will execute.

Step Requirements

The following requirements apply to each container image referenced in a steps field:
  • The container image must abide by the container contract
  • Each container image runs to completion or until the first failure occurs
  • The CPU, memory, and ephemeral storage resource requests set on Steps will be adjusted to comply with any LimitRanges present in the Namespace

Setting Resource Limits

Running Scripts in Steps

A step can specify a script field, which contains the body of a script. That script is invoked as if it were stored inside the container image, and any args are passed directly to it.
If the script field is present, the step cannot also contain a command field.
Scripts that do not start with a shebang line will have the following default preamble prepended:

Bash Script Example

Python Script Example

Node Script Example

Parameters

You can specify parameters that you want to supply to the Task at execution time. Parameters are passed to the Task from its corresponding TaskRun.

Parameter Name Format

Parameter names:
  • Must only contain alphanumeric characters, hyphens (-), underscores (_), and dots (.)
  • Must begin with a letter or an underscore (_)
  • Are case insensitive
Object parameter names and their key names cannot contain dots (.).

Parameter Types

Each declared parameter has a type field, which can be set to string, array, or object.

String Type

If not specified, the type field defaults to string.

Array Type

array type is useful when the number of compilation flags being supplied to a Task varies throughout execution.

Object Type

object type is useful when you want to group related parameters.
Object parameters must specify the properties section to define the schema.

Parameter Example

Workspaces

Workspaces allow you to specify one or more volumes that each Task requires during execution.
For more information, see the Workspaces documentation.

Results

A Task can emit string results that can be viewed by users and passed to other Tasks in a Pipeline. Task results are best suited for holding small amounts of data, such as commit SHAs, branch names, ephemeral namespaces, and so on.

Defining Results

Array Results

Tasks can also emit array results:
The opening and closing square brackets are mandatory along with escaped JSON.

Object Results

Tasks can emit object results:

Result Size Limits

The maximum size of a Task’s results is limited by the container termination message feature of Kubernetes, currently 4096 bytes. The more steps you have in a Task, the smaller the result for each step can be.
For larger results, consider using Workspaces to store and pass data between Tasks within a Pipeline.

Sidecars

The sidecars field specifies a list of Containers to run alongside the Steps in your Task. You can use Sidecars to provide auxiliary functionality, such as Docker in Docker or running a mock API server.

Variable Substitution

Tekton provides variables to inject values into the contents of certain fields. The mechanism is simple - string replacement is performed by the Tekton Controller when a TaskRun is executed.

Available Variables

  • $(params.<name>) - Access parameter values
  • $(workspaces.<name>.path) - Path to a Workspace
  • $(workspaces.<name>.bound) - Whether a workspace was bound (true/false)
  • $(workspaces.<name>.claim) - Name of the PersistentVolumeClaim
  • $(workspaces.<name>.volume) - Name of the Volume
  • $(results.<name>.path) - Path where results are written
  • $(steps.<step-name>.exitCode.path) - Path to a step’s exit code

Examples