Cleaning up with finally
On that last pipeline run, a fatal error occurred. It tried to clone the repository, but Git requires an empty directory to clone the files into. The folder already had files from the previous clone operation.
To avoid those errors and ensure that you always start from a clean slate, you will need to clean up your persisting workspaces when the pipeline run has terminated. To do so, you will need to add a cleanup task. You will also need to ensure this task runs at the end of the pipeline, even if an error terminated the pipeline before it completed its run. This is where the finally
tasks will come into play.
In this section, you will add a cleanup task to your pipeline that will remove all the files from the workspace:
- Create a new file called
cleanup.yaml
. In here, create a new task namedcleanup
:apiVersion: tekton.dev/v1beta1 kind: Task metadata: name: cleanup spec:
- Just like the other tasks you've built in this...