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
ATaskRun executes the Steps in the Task in the order they are specified until all Steps have executed successfully or a failure occurs.
TaskRun Configuration
ATaskRun 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
TaskRun object.Specifies the metadata that uniquely identifies the TaskRun, such as a
name.Specifies the configuration for the TaskRun.
Specifies the
Task that the TaskRun will execute (use either taskRef or taskSpec).Embeds the
Task definition directly in the TaskRun (use either taskRef or taskSpec).Optional Fields
Specifies a ServiceAccount object that provides custom credentials for executing the TaskRun.
Specifies the desired execution parameters for the Task.
Specifies the timeout before the TaskRun fails.
Specifies a Pod template to use as the starting point for configuring the Pods for the Task.
Specifies the physical volumes to use for the Workspaces declared by a Task.
Specifies the number of times to retry the TaskRun execution when it fails.
Specifies any breakpoints and debugging configuration for the Task execution.
Specifying the Target Task
Using taskRef
To specify theTask you want to execute in your TaskRun, use the taskRef field:
Using taskSpec
You can also embed the desiredTask definition directly in the TaskRun using the taskSpec field:
Specifying Parameters
If aTask 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 inlinedtaskSpec, parameters from the parent TaskRun will be available to the Task without needing to be explicitly defined:
Specifying Workspaces
If aTask specifies one or more Workspaces, you must map those Workspaces to the corresponding physical volumes in your TaskRun definition:
Workspace Volume Sources
- PersistentVolumeClaim
- emptyDir
- ConfigMap
- Secret
Configuring Failure Timeout
You can use thetimeout 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.
TaskRun runs longer than its timeout value, the pod associated with the TaskRun will be deleted.
Specifying Retries
You can use theretries field to set how many times you want to retry on a failed TaskRun. All TaskRun failures are retriable except for Cancellation.
TaskRun, when an error occurs:
- The error status is archived in
status.RetriesStatus - The
Succeededcondition is updated with statusUnknownand reasonToBeRetried status.StartTime,status.PodNameandstatus.Resultsare unset to trigger another retry attempt
Specifying ServiceAccount
You can execute theTask 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
Thestatus field defines the observed state of TaskRun.
Status Fields
Contains the latest observations of the TaskRun’s state.
Name of the pod containing the containers responsible for executing this task’s steps.
The time at which the TaskRun began executing, in RFC3339 format.
The time at which the TaskRun finished executing, in RFC3339 format.
List of results written out by the task’s containers.
Contains the state of each step container.
Status Example
Overall Status
| status | reason | message | completionTime | Description |
|---|---|---|---|---|
| Unknown | Started | n/a | No | TaskRun has just been picked up by the controller |
| Unknown | Running | n/a | No | TaskRun has been validated and started to perform its work |
| True | Succeeded | n/a | Yes | TaskRun completed successfully |
| False | Failed | n/a | Yes | TaskRun failed because one of the steps failed |
| False | TaskRunTimeout | n/a | Yes | TaskRun timed out |
Cancelling a TaskRun
To cancel aTaskRun that’s currently executing, update its status to mark it as cancelled:
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 breakpointdebug-fail-continue- Mark the step as a failure and exit the breakpoint