Adding a finally task
So far, all the pipelines that you built did not persist any data. Once the pods were terminated everything was taken down with them, and the next run always started from a fresh environment.
This won't always be the case. Most of the time, you will clone a code repository and store it on a PersistentVolumeClaim (PVC) for all tasks to access it. This exact scenario will be introduced in Chapter 7, Sharing Data with Workspaces. When you start using workspaces, you will need to clean up your persisted data to start with a clean environment each time. This is where finally
tasks will come into play.
Those tasks will always be executed, even after there was a task that failed in the pipeline. Let's demonstrate this:
- Create a new file called
cleanup.yaml
and create a task calledcleanup
:apiVersion: tekton.dev/v1beta1 kind: Task metadata: name: cleanup spec:
- This task has a single step named
clean
. It uses a UBI to execute...