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
ATask 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.
Task declaration includes the following elements:
Task Configuration
ATask definition supports the following fields:
Required Fields
Specifies the API version. For example,
tekton.dev/v1 or tekton.dev/v1beta1.Identifies this resource object as a
Task object.Specifies metadata that uniquely identifies the Task resource object. For example, a
name.Specifies the configuration information for this Task resource object.
Specifies one or more container images to run in the Task.
Optional Fields
An informative description of the Task.
Specifies execution parameters for the Task.
Specifies paths to volumes required by the Task.
Specifies the names under which Tasks write execution results.
Specifies one or more volumes that will be available to the Steps in the Task.
Specifies a Container step definition to use as the basis for all Steps in the Task.
Specifies Sidecar containers to run alongside the Steps in the Task.
Example Task Definition
Steps
AStep 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 asteps 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
- v1
- v1beta1
Running Scripts in Steps
A step can specify ascript 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.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
Parameter Types
Each declared parameter has atype field, which can be set to string, array, or object.
String Type
If not specified, thetype 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.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
For larger results, consider using Workspaces to store and pass data between Tasks within a Pipeline.Sidecars
Thesidecars 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