PipelineRuns
This document defines PipelineRuns
and their capabilities.
On its own, a Pipeline
declares what Tasks
torun, and the order they run in. To execute the Tasks
in the Pipeline
, you must create a PipelineRun
.
Creation of a PipelineRun
will trigger the creation ofTaskRuns
for each Task
in your pipeline.
Syntax
To define a configuration file for a PipelineRun
resource, you can specify thefollowing fields:
- Required:
apiVersion
- Specifies the API version, for exampletekton.dev/vbeta1
kind
- Specify thePipelineRun
resource object.metadata
- Specifies data to uniquely identify thePipelineRun
resource object, for example aname
.spec
- Specifies the configuration information foryourPipelineRun
resource object.pipelineRef
orpipelineSpec
- Specifies thePipeline
you want to run.
- Optional:
resources
- Specifies whichPipelineResources
to use for thisPipelineRun
.params
- Specifies which params to be passed to the pipeline specified/referenced by this pipeline run.serviceAccountName
- Specifies aServiceAccount
resourceobject that enables your build to run with the defined authenticationinformation. When aServiceAccount
isn’t specified, thedefault-service-account
specified in the configmap - config-defaults will be applied.serviceAccountNames
- Specifies a list ofserviceAccountName
andPipelineTask
pairs that enable you to overwrite aServiceAccount
for a concretePipelineTask
.timeout
- Specifies timeout after which thePipelineRun
will fail. If the value oftimeout
is empty, the default timeout will be applied. If the value is set to 0,there is no timeout.PipelineRun
shares the same default timeout asTaskRun
. You canfollow the instruction here to configure thedefault timeout, the same way asTaskRun
.podTemplate
- Specifies a pod template that will be used as the basis for theTask
pod.
Specifying a pipeline
Since a PipelineRun
is an invocation of a Pipeline
, you must specifywhat Pipeline
to invoke.
You can do this by providing a reference to an existing Pipeline
:
spec:
pipelineRef:
name: mypipeline
Or you can embed the spec of the Pipeline
directly in the PipelineRun
:
spec:
pipelineSpec:
tasks:
- name: task1
taskRef:
name: mytask
Here is a sample PipelineRun
to display differentgreetings while embedding the spec of the Pipeline
directly in the PipelineRun
.
After creating such a PipelineRun
, the logs from this pod are displaying morning greetings:
kubectl logs $(kubectl get pods -o name | grep pipelinerun-echo-greetings-echo-good-morning)
Good Morning, Bob!
And the logs from this pod are displaying evening greetings:
kubectl logs $(kubectl get pods -o name | grep pipelinerun-echo-greetings-echo-good-night)
Good Night, Bob!
Even further you can embed the spec of a Task
directly in the Pipeline
:
spec:
pipelineSpec:
tasks:
- name: task1
taskSpec:
steps:
...
Here is a sample PipelineRun
with embeddedthe spec of the Pipeline
directly in the PipelineRun
along with the spec of the Task
under PipelineSpec
.
Resources
When running a Pipeline
, you will need to specify thePipelineResources
to use with it. One Pipeline
may need tobe run with different PipelineResources
in cases such as:
- When triggering the run of a
Pipeline
against a pull request, the triggeringsystem must specify the commit-ish of a gitPipelineResource
to use - When invoking a
Pipeline
manually against one’s own setup, one will need toensure one’s own GitHub fork (via the gitPipelineResource
), imageregistry (via the imagePipelineResource
) and Kubernetes cluster (via theclusterPipelineResource
).
Specify the PipelineResources
in the PipelineRun
using the resources
sectionin the PipelineRun’s spec, for example:
spec:
resources:
- name: source-repo
resourceRef:
name: skaffold-git
- name: web-image
resourceRef:
name: skaffold-image-leeroy-web
- name: app-image
resourceRef:
name: skaffold-image-leeroy-app
Or you can embed the spec of the Resource
directly in the PipelineRun
:
spec:
resources:
- name: source-repo
resourceSpec:
type: git
params:
- name: revision
value: v0.32.0
- name: url
value: https://github.com/GoogleContainerTools/skaffold
- name: web-image
resourceSpec:
type: image
params:
- name: url
value: gcr.io/christiewilson-catfactory/leeroy-web
- name: app-image
resourceSpec:
type: image
params:
- name: url
value: gcr.io/christiewilson-catfactory/leeroy-app
Params
While writing a Pipelinerun, we can specify params that need to be bound tothe input params of the pipeline specified/referenced by the Pipelinerun.
This means that a Pipeline can be run with different input params, by writing Pipelinerunswhich bound different input values to the Pipeline params.
spec:
params:
- name: pl-param-x
value: "100"
- name: pl-param-y
value: "500"
Service Account
Specifies the name
of a ServiceAccount
resource object. Use theserviceAccountName
field to run your Pipeline
with the privileges of thespecified service account. If no serviceAccountName
field is specified, yourresulting TaskRuns
run using the service account specified in the ConfigMapconfigmap-defaults
which if absent will default to thedefault
service accountthat is in the namespaceof the TaskRun
resource object.
For examples and more information about specifying service accounts, see theServiceAccount
reference topic.
Service Accounts
Specifies the list of serviceAccountName
and PipelineTask
pairs. A specifiedPipelineTask
will be run with the configured ServiceAccount
,overwriting the serviceAccountName
configuration, for example:
spec:
serviceAccountName: sa-1
serviceAccountNames:
- taskName: build-task
serviceAccountName: sa-for-build
If used with this Pipeline
, test-task
will use the ServiceAccount
sa-1
, while build-task
will use sa-for-build
.
kind: Pipeline
spec:
tasks:
- name: build-task
taskRef:
name: build-push
- name: test-task
taskRef:
name: test
Pod Template
Specifies a pod template configuration that will be used as the basis for the Task
pod. Thisallows to customize some Pod specific field per Task
execution, aka TaskRun
.
In the following example, the Task
is defined with a volumeMount
(my-cache
), that is provided by the PipelineRun
, using apersistentVolumeClaim
. The Pod will also run as a non-root user.
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: mytask
spec:
steps:
- name: writesomething
image: ubuntu
command: ["bash", "-c"]
args: ["echo 'foo' > /my-cache/bar"]
volumeMounts:
- name: my-cache
mountPath: /my-cache
---
apiVersion: tekton.dev/v1beta1
kind: Pipeline
metadata:
name: mypipeline
spec:
tasks:
- name: task1
taskRef:
name: mytask
---
apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
name: mypipelinerun
spec:
pipelineRef:
name: mypipeline
podTemplate:
securityContext:
runAsNonRoot: true
volumes:
- name: my-cache
persistentVolumeClaim:
claimName: my-volume-claim
PersistentVolumeClaims
Any persistent volume claims within a PipelineRun
are bound until thecorresponding PipelineRun
or pods are deleted. This also applies to anyinternally generated persistent volume claims.
Workspaces
For a PipelineRun
to execute a Pipeline
that declares workspaces
it needs to mapthose workspaces
to actual physical volumes.
Here are the relevant fields of a PipelineRun
spec when providing aPersistentVolumeClaim
as a workspace:
workspaces:
- name: myworkspace # must match workspace name in Task
persistentVolumeClaim:
claimName: mypvc # this PVC must already exist
subPath: my-subdir
For more examples and complete documentation on configuring workspaces
inPipelineRun
s see workspaces.md.
Tekton supports several different kinds of Volume
in Workspaces
. For a list ofthe different kinds see the section onVolumeSources
for Workspaces.
For a complete example see the Workspaces PipelineRunin the examples directory.
Cancelling a PipelineRun
In order to cancel a running pipeline (PipelineRun
), you need to update itsspec to mark it as cancelled. Related TaskRun
instances will be marked ascancelled and running Pods will be deleted.
apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
name: go-example-git
spec:
# […]
status: "PipelineRunCancelled"
LimitRanges
In order to request the minimum amount of resources needed to support the containersfor steps
that are part of a TaskRun
, Tekton only requests the maximum values for CPU,memory, and ephemeral storage from the steps
that are part of a TaskRun. Only the maxresource request values are needed since steps
only execute one at a time in a TaskRun
pod.All requests that are not the max values are set to zero as a result.
When a LimitRange is present in a namespacewith a minimum set for container resource requests (i.e. CPU, memory, and ephemeral storage) where PipelineRuns
are attempting to run, Tekton will search through all LimitRanges present in the namespace and use the minimumset for container resource requests instead of requesting 0.
An example PipelineRun
with a LimitRange is available here.