Pipeline is one of the core building blocks in designing a CI/CD use case on Kubernetes with Tekton. A Tekton Pipeline is a collection of tasks, which run based on how they are arranged. These tasks can be represented as a graph in which each node represents a task and can be arranged in many different ways.
task-A
, task-B
, and task-C
) in parallel. The three tasks start running independently and finish irrespective of the success or failure of other tasks. This kind of arrangement applies to a CI/CD use case, such as running unit tests and integration tests in parallel. tasks:
- name: task-A
taskRef:
name: task1
- name: task-B
taskRef:
name: task2
- name: task-C
taskRef:
name: task3
Show more
Design sequence of tasks that run one after each other by using runAfter
. For example, PipelineRun
instantiates build-image
and waits for it to finish. If build-image
exits with success, PipelineRun
instantiates e2e-tests
, otherwise PipelineRun
exits with failure without running the rest of the tasks. The same process applies to the next task. This example is the ideal arrangement, but hardly works in real world. It’s very common to run into task failures and require further processing if such failures.
tasks:
- name: build-image
taskRef:
name: build-image
- name: e2e-tests
runAfter: [ build-image ]
taskRef:
name: e2e-tests
- name: deploy
runAfter: [ e2e-tests ]
taskRef:
name: deploy
Show more
Design failure strategies by using finally
. PipelineRun
runs tasks that are specified under the finally
section after all tasks under tasks
section are completed regardless success or failure. For example, finally
tasks start running after all tasks are completed successfully or one of the tasks exits with failure. finally
tasks run in parallel just before they exit the PipelineRun
. The PipelineRun
exit status contains TaskRuns
for all tasks, including the finally
tasks.
tasks:
- name: build-image
taskRef:
name: build-image
- name: e2e-tests
runAfter: [ build-image ]
taskRef:
name: e2e-tests
- name: deploy
runAfter: [ e2e-tests ]
taskRef:
name: deploy
finally:
- name: cleanup
taskRef:
name: cleanup
So far, this looks great, but what about running a check before you run a task? You can design PipelineRun
to include conditional tasks by using the Condition
CRD to run a check before you run that task. The Condition
CRD, just like a task
, creates a new pod
in a Kubernetes cluster to run that check. Depending on the outcome of that Condition
CRD, a task is run or declared a failure
with a conditionCheckFailed
.
#devops #tekton