generated from ibm-developer-skills-network/coding-project-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtasks.yaml
35 lines (34 loc) · 1.2 KB
/
tasks.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: cleanup
spec:
description: This task will clean up a workspace by deleting all of the files.
workspaces:
- name: source
steps:
- name: remove
image: alpine:3
env:
- name: WORKSPACE_SOURCE_PATH
value: $(workspaces.source.path)
workingDir: $(workspaces.source.path)
securityContext:
runAsNonRoot: false
runAsUser: 0
script: |
#!/usr/bin/env sh
set -eu
echo "Removing all files from ${WORKSPACE_SOURCE_PATH} ..."
# Delete any existing contents of the directory if it exists.
#
# We don't just "rm -rf ${WORKSPACE_SOURCE_PATH}" because ${WORKSPACE_SOURCE_PATH} might be "/"
# or the root of a mounted volume.
if [ -d "${WORKSPACE_SOURCE_PATH}" ] ; then
# Delete non-hidden files and directories
rm -rf "${WORKSPACE_SOURCE_PATH:?}"/*
# Delete files and directories starting with . but excluding ..
rm -rf "${WORKSPACE_SOURCE_PATH}"/.[!.]*
# Delete files and directories starting with .. plus any other character
rm -rf "${WORKSPACE_SOURCE_PATH}"/..?*
fi