Pipelines
This document defines Pipelines
and their capabilities.
Syntax
To define a configuration file for a Pipeline
resource, you can specify thefollowing fields:
- Required:
apiVersion
- Specifies the API version, for exampletekton.dev/v1beta1
.kind
- Specify thePipeline
resource object.metadata
- Specifies data to uniquely identify thePipeline
resource object, for example aname
.spec
- Specifies the configuration information foryourPipeline
resource object. In order for aPipeline
to do anything,the spec must include:tasks
- Specifies whichTasks
to run and how to runthem
- Optional:
description
- Description of the Pipeline.resources
- Specifies whichPipelineResources
of which types thePipeline
will beusing in its Taskstasks
resources.inputs
/resource.outputs
from
- Used when the content of thePipelineResource
should come from theoutput of a previous Pipeline Task
runAfter
- Used when the Pipeline Taskshould be executed after another Pipeline Task, but there is nooutput linking requiredretries
- Used when the task is wanted to be executed ifit fails. Could be a network error or a missing dependency. It does notapply to cancellations.conditions
- Used when a task is to be executed only if the specifiedconditions are evaluated to be true.timeout
- Specifies timeout after which theTaskRun
for a Pipeline Task willfail. There is no default timeout for a Pipeline Task timeout. If no timeout is specified forthe Pipeline Task, the only timeout taken into account for running aPipeline
will be atimeout for thePipelineRun
.
Description
The description
field is an optional field and can be used to provide description of the Pipeline.
Declared resources
In order for a Pipeline
to interact with the outside world, it will probablyneed PipelineResources
which will be given toTasks
as inputs and outputs.
Your Pipeline
must declare the PipelineResources
it needs in a resources
section in the spec
, giving each a name which will be used to refer to thesePipelineResources
in the Tasks
.
For example:
spec:
resources:
- name: my-repo
type: git
- name: my-image
type: image
Workspaces
workspaces
are a way of declaring volumes you expect to be made available to yourexecuting Pipeline
and its Task
s.
Here’s a short example of a Pipeline Spec with workspaces
:
spec:
workspaces:
- name: pipeline-ws1 # The name of the workspace in the Pipeline
tasks:
- name: use-ws-from-pipeline
taskRef:
name: gen-code # gen-code expects a workspace with name "output"
workspaces:
- name: output
workspace: pipeline-ws1
- name: use-ws-again
taskRef:
name: commit # commit expects a workspace with name "src"
runAfter:
- use-ws-from-pipeline # important: use-ws-from-pipeline writes to the workspace first
workspaces:
- name: src
workspace: pipeline-ws1
For complete documentation on using workspaces
in Pipeline
s, seeworkspaces.md.
For a complete example see the Workspaces PipelineRunin the examples directory.
Parameters
Pipeline
s can declare input parameters that must be supplied to the Pipeline
during a PipelineRun
. Pipeline parameters can be used to replace templatevalues in PipelineTask
parameters’ values.
Parameter names are limited to alpha-numeric characters, -
and and canonly start with alpha characters and
. For example,
fooIs-Bar_
is a validparameter name, barIsBa$
or 0banana
are not.
Each declared parameter has a type
field, assumed to be string
if not provided by the user. The other possible type is array
— useful, for instance, when a dynamic number of string arguments need to be supplied to a task. When the actual parameter value is supplied, its parsed type is validated against the type
field.
Usage
The following example shows how Pipeline
s can be parameterized, and theseparameters can be passed to the Pipeline
from a PipelineRun
.
Input parameters in the form of $(params.foo)
are replaced inside of thePipelineTask
parameters’ values (see alsovariable substitution).
The following Pipeline
declares an input parameter called ‘context’, and usesit in the PipelineTask
’s parameter. The description
and default
fields fora parameter are optional, and if the default
field is specified and thisPipeline
is used by a PipelineRun
without specifying a value for ‘context’,the default
value will be used.
apiVersion: tekton.dev/v1beta1
kind: Pipeline
metadata:
name: pipeline-with-parameters
spec:
params:
- name: context
type: string
description: Path to context
default: /some/where/or/other
tasks:
- name: build-skaffold-web
taskRef:
name: build-push
params:
- name: pathToDockerFile
value: Dockerfile
- name: pathToContext
value: "$(params.context)"
The following PipelineRun
supplies a value for context
:
apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
name: pipelinerun-with-parameters
spec:
pipelineRef:
name: pipeline-with-parameters
params:
- name: "context"
value: "/workspace/examples/microservices/leeroy-web"
Pipeline Tasks
A Pipeline
will execute a graph of Tasks
(seeordering for how to express this graph). A valid Pipeline
declaration must include a reference to at least one Task
. EachTask
within a Pipeline
must have avalidname and task reference, for example:
tasks:
- name: build-the-image
taskRef:
name: build-push
Declared PipelineResources
can be given to Task
s inthe Pipeline
as inputs and outputs, for example:
spec:
tasks:
- name: build-the-image
taskRef:
name: build-push
resources:
inputs:
- name: workspace
resource: my-repo
outputs:
- name: image
resource: my-image
Parameters can also be provided:
spec:
tasks:
- name: build-skaffold-web
taskRef:
name: build-push
params:
- name: pathToDockerFile
value: Dockerfile
- name: pathToContext
value: /workspace/examples/microservices/leeroy-web
from
Sometimes you will have Pipeline Tasks that need to take asinput the output of a previous Task
, for example, an image built by a previousTask
.
Express this dependency by adding from
on PipelineResources
that your Tasks
need.
- The (optional)
from
key on aninput source
defines a set of previousPipelineTasks
(i.e. the named instance of aTask
) in thePipeline
- When the
from
key is specified on an input source, the version of theresource that is from the defined list of tasks is used from
can support fan in and fan out- The
from
clause expresses ordering, i.e. thePipeline Task which provides thePipelineResource
must runbefore the Pipeline Task which needs thatPipelineResource
as an input- The name of the
PipelineResource
must correspond to aPipelineResource
from theTask
that the referencedPipelineTask
gives as an output
- The name of the
For example see this Pipeline
spec:
- name: build-app
taskRef:
name: build-push
resources:
outputs:
- name: image
resource: my-image
- name: deploy-app
taskRef:
name: deploy-kubectl
resources:
inputs:
- name: image
resource: my-image
from:
- build-app
The resource my-image
is expected to be given to the deploy-app
Task
fromthe build-app
Task
. This means that the PipelineResource
my-image
mustalso be declared as an output of build-app
.
This also means that the build-app
Pipeline Task will run before deploy-app
,regardless of the order they appear in the spec.
runAfter
Sometimes you will need to have Pipeline Tasks that need torun in a certain order, but they do not have an explicitoutput to input dependency (which isexpressed via from
). In this case you can use runAfter
to indicatethat a Pipeline Task should be run after one or more previous Pipeline Tasks.
For example see this Pipeline
spec:
- name: test-app
taskRef:
name: make-test
resources:
inputs:
- name: workspace
resource: my-repo
- name: build-app
taskRef:
name: kaniko-build
runAfter:
- test-app
resources:
inputs:
- name: workspace
resource: my-repo
In this Pipeline
, we want to test the code before we build from it, but thereis no output from test-app
, so build-app
uses runAfter
to indicate thattest-app
should run before it, regardless of the order they appear in thespec.
retries
Sometimes you need a policy for retrying tasks which have problems such asnetwork errors, missing dependencies or upload problems. Any of those issues mustbe reflected as False (corev1.ConditionFalse) within the TaskRun StatusSucceeded Condition. For that reason there is an optional attribute calledretries
which declares how many times that task should be retried in case offailure.
By default and in its absence there are no retries; its value is 0.
tasks:
- name: build-the-image
retries: 1
taskRef:
name: build-push
In this example, the task “build-the-image” will be executed and if the firstrun fails a second one would triggered. But, if that fails no more wouldtriggered: a max of two executions.
conditions
Sometimes you will need to run tasks only when some conditions are true. The conditions
fieldallows you to list a series of references to Conditions
that are run before the taskis run. If all of the conditions evaluate to true, the task is run. If any of the conditions are false,the Task is not run. Its status.ConditionSucceeded is set to False with the reason set to ConditionCheckFailed
.However, unlike regular task failures, condition failures do not automatically fail the entire pipelinerun – other tasks that are not dependent on the task (via from
or runAfter
) are still run.
tasks:
- name: conditional-task
taskRef:
name: build-push
conditions:
- conditionRef: my-condition
params:
- name: my-param
value: my-value
resources:
- name: workspace
resource: source-repo
In this example, my-condition
refers to a Condition custom resource. The build-push
task will only be executed if the condition evaluates to true.
Resources in conditions can also use the from
field to indicate that theyexpect the output of a previous task as input. As with regular Pipeline Tasks, using from
implies ordering – if task has a condition that takes in an output resource fromanother task, the task producing the output resource will run first:
tasks:
- name: first-create-file
taskRef:
name: create-file
resources:
outputs:
- name: workspace
resource: source-repo
- name: then-check
conditions:
- conditionRef: "file-exists"
resources:
- name: workspace
resource: source-repo
from: [first-create-file]
taskRef:
name: echo-hello
Timeout
The Timeout property of a Pipeline Task allows a timeout to be defined for a TaskRun
thatis part of a PipelineRun
. If the TaskRun
exceeds the amount of time specified, the TaskRun
will fail and the PipelineRun
associated with a Pipeline
will fail as well.
There is no default timeout for Pipeline Tasks, so a timeout must be specified with a Pipeline Taskwhen defining a Pipeline
if one is needed. An example of a Pipeline Task with a Timeout is shown below:
spec:
tasks:
- name: build-the-image
taskRef:
name: build-push
Timeout: "0h1m30s"
The Timeout property is specified as part of the Pipeline Task on the Pipeline
spec. The aboveexample has a timeout of one minute and 30 seconds.
Results
Tasks can declare results that they will emit during their execution. These results can be used as values for params in subsequent tasks of a Pipeline. Tekton will infer the ordering of these Tasks to ensure that the Task emitting the results runs before the Task consuming those results in its parameters.
Using a Task result as a value for another Task’s parameter is done with variable substitution. Here is what a Pipeline Task’s param looks like with a result wired into it:
params:
- name: foo
value: "$(tasks.previous-task-name.results.bar-result)"
In this example the previous pipeline task has name “previous-task-name” and its result is declared in the Task definition as having name “bar-result”.
For a complete example demonstrating Task Results in a Pipeline see the pipelinerun example.
Ordering
The Pipeline Tasks in a Pipeline
can be connected and runin a graph, specifically a Directed Acyclic Graph or DAG. Each of the PipelineTasks is a node, which can be connected with an edge (i.e. a Graph) such that one will runbefore another (i.e. Directed), and the execution will eventually complete(i.e. Acyclic, it will not get caught in infinite loops).
This is done using:
from
clauses on thePipelineResources
needed by aTask
runAfter
clauses on the Pipeline Tasks
For example see this Pipeline
spec:
- name: lint-repo
taskRef:
name: pylint
resources:
inputs:
- name: workspace
resource: my-repo
- name: test-app
taskRef:
name: make-test
resources:
inputs:
- name: workspace
resource: my-repo
- name: build-app
taskRef:
name: kaniko-build-app
runAfter:
- test-app
resources:
inputs:
- name: workspace
resource: my-repo
outputs:
- name: image
resource: my-app-image
- name: build-frontend
taskRef:
name: kaniko-build-frontend
runAfter:
- test-app
resources:
inputs:
- name: workspace
resource: my-repo
outputs:
- name: image
resource: my-frontend-image
- name: deploy-all
taskRef:
name: deploy-kubectl
resources:
inputs:
- name: my-app-image
resource: my-app-image
from:
- build-app
- name: my-frontend-image
resource: my-frontend-image
from:
- build-frontend
This will result in the following execution graph:
| |
v v
test-app lint-repo
/ \
v v
build-app build-frontend
\ /
v v
deploy-all
- The
lint-repo
andtest-app
Pipeline Tasks will begin executingsimultaneously. (They have nofrom
orrunAfter
clauses.) - Once
test-app
completes, bothbuild-app
andbuild-frontend
will beginexecuting simultaneously (bothrunAfter
test-app
). - When both
build-app
andbuild-frontend
have completed,deploy-all
willexecute (it requiresPipelineResources
from both Pipeline Tasks). - The entire
Pipeline
will be finished executing afterlint-repo
anddeploy-all
have completed.
Examples
For complete examples, seethe examples folder.