Skip to main content
A TaskRun allows you to instantiate and execute a Task on-cluster. A Task specifies one or more Steps that execute container images and each container image performs a specific piece of build work.

Overview

A TaskRun executes the Steps in the Task in the order they are specified until all Steps have executed successfully or a failure occurs.

TaskRun Configuration

A TaskRun 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 TaskRun object.
object
required
Specifies the metadata that uniquely identifies the TaskRun, such as a name.
object
required
Specifies the configuration for the TaskRun.
object
Specifies the Task that the TaskRun will execute (use either taskRef or taskSpec).
object
Embeds the Task definition directly in the TaskRun (use either taskRef or taskSpec).

Optional Fields

string
Specifies a ServiceAccount object that provides custom credentials for executing the TaskRun.
array
Specifies the desired execution parameters for the Task.
string
Specifies the timeout before the TaskRun fails.
object
Specifies a Pod template to use as the starting point for configuring the Pods for the Task.
array
Specifies the physical volumes to use for the Workspaces declared by a Task.
integer
Specifies the number of times to retry the TaskRun execution when it fails.
object
Specifies any breakpoints and debugging configuration for the Task execution.

Specifying the Target Task

Using taskRef

To specify the Task you want to execute in your TaskRun, use the taskRef field:

Using taskSpec

You can also embed the desired Task definition directly in the TaskRun using the taskSpec field:

Specifying Parameters

If a Task has parameters, you can use the params field to specify their values:
If a parameter does not have an implicit default value, you must explicitly set its value.

Propagated Parameters

When using an inlined taskSpec, parameters from the parent TaskRun will be available to the Task without needing to be explicitly defined:

Specifying Workspaces

If a Task specifies one or more Workspaces, you must map those Workspaces to the corresponding physical volumes in your TaskRun definition:

Workspace Volume Sources

Configuring Failure Timeout

You can use the timeout field to set the TaskRun's desired timeout value. The timeout is a duration conforming to Go’s ParseDuration format. For example, valid values are 1h30m, 1h, 1m, and 60s.
If a TaskRun runs longer than its timeout value, the pod associated with the TaskRun will be deleted.
When a TaskRun times out, the logs of the TaskRun are not preserved as the pod is deleted.

Specifying Retries

You can use the retries field to set how many times you want to retry on a failed TaskRun. All TaskRun failures are retriable except for Cancellation.
For a retriable TaskRun, when an error occurs:
  • The error status is archived in status.RetriesStatus
  • The Succeeded condition is updated with status Unknown and reason ToBeRetried
  • status.StartTime, status.PodName and status.Results are unset to trigger another retry attempt

Specifying ServiceAccount

You can execute the Task in your TaskRun with a specific set of credentials by specifying a ServiceAccount object name:

Pod Template

You can specify a Pod template configuration that will serve as the configuration starting point for the Pod in which the container images specified in your Task will execute:

TaskRun Status

The status field defines the observed state of TaskRun.

Status Fields

array
Contains the latest observations of the TaskRun’s state.
string
Name of the pod containing the containers responsible for executing this task’s steps.
string
The time at which the TaskRun began executing, in RFC3339 format.
string
The time at which the TaskRun finished executing, in RFC3339 format.
array
List of results written out by the task’s containers.
array
Contains the state of each step container.

Status Example

Overall Status

Cancelling a TaskRun

To cancel a TaskRun that’s currently executing, update its status to mark it as cancelled:
When you cancel a TaskRun, the running pod associated with that TaskRun is deleted. This means that the logs of the TaskRun are not preserved.

Debugging a TaskRun

Breakpoint on Failure

TaskRuns can be halted on failure for troubleshooting:

Debug Environment

After accessing the container environment, you can use the following scripts in the /tekton/debug/scripts directory:
  • debug-continue - Mark the step as a success and exit the breakpoint
  • debug-fail-continue - Mark the step as a failure and exit the breakpoint

Example TaskRun with Referenced Task

Example TaskRun with Embedded Task