Skip to content

Commit 581185a

Browse files
authored
Merge pull request ibm-developer-skills-network#15 from ibm-developer-skills-network/add-init-task
Added init task to clean workspace
2 parents 42a50b5 + 972c81b commit 581185a

File tree

6 files changed

+138
-0
lines changed

6 files changed

+138
-0
lines changed

labs/04_unit_test_automation/pipeline.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ spec:
1010
- name: branch
1111
default: master
1212
tasks:
13+
- name: init
14+
workspaces:
15+
- name: source
16+
workspace: pipeline-workspace
17+
taskRef:
18+
name: cleanup
19+
1320
- name: clone
1421
workspaces:
1522
- name: output
@@ -21,6 +28,8 @@ spec:
2128
value: $(params.repo-url)
2229
- name: revision
2330
value: $(params.branch)
31+
runAfter:
32+
- init
2433

2534
- name: lint
2635
taskRef:

labs/04_unit_test_automation/tasks.yaml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,40 @@ spec:
1212
image: alpine:3
1313
command: [/bin/echo]
1414
args: ["$(params.message)"]
15+
16+
---
17+
apiVersion: tekton.dev/v1beta1
18+
kind: Task
19+
metadata:
20+
name: cleanup
21+
spec:
22+
description: This task will clean up a workspace by deleting all of the files.
23+
workspaces:
24+
- name: source
25+
steps:
26+
- name: remove
27+
image: alpine:3
28+
env:
29+
- name: WORKSPACE_SOURCE_PATH
30+
value: $(workspaces.source.path)
31+
workingDir: $(workspaces.source.path)
32+
securityContext:
33+
runAsNonRoot: false
34+
runAsUser: 0
35+
script: |
36+
#!/usr/bin/env sh
37+
set -eu
38+
echo "Removing all files from ${WORKSPACE_SOURCE_PATH} ..."
39+
# Delete any existing contents of the directory if it exists.
40+
#
41+
# We don't just "rm -rf ${WORKSPACE_SOURCE_PATH}" because ${WORKSPACE_SOURCE_PATH} might be "/"
42+
# or the root of a mounted volume.
43+
if [ -d "${WORKSPACE_SOURCE_PATH}" ] ; then
44+
# Delete non-hidden files and directories
45+
rm -rf "${WORKSPACE_SOURCE_PATH:?}"/*
46+
# Delete files and directories starting with . but excluding ..
47+
rm -rf "${WORKSPACE_SOURCE_PATH}"/.[!.]*
48+
# Delete files and directories starting with .. plus any other character
49+
rm -rf "${WORKSPACE_SOURCE_PATH}"/..?*
50+
fi
51+

labs/05_build_an_image/pipeline.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ spec:
1010
- name: branch
1111
default: master
1212
tasks:
13+
- name: init
14+
workspaces:
15+
- name: source
16+
workspace: pipeline-workspace
17+
taskRef:
18+
name: cleanup
19+
1320
- name: clone
1421
workspaces:
1522
- name: output
@@ -21,6 +28,8 @@ spec:
2128
value: $(params.repo-url)
2229
- name: revision
2330
value: $(params.branch)
31+
runAfter:
32+
- init
2433

2534
- name: lint
2635
workspaces:

labs/05_build_an_image/tasks.yaml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,43 @@ spec:
1212
image: alpine:3
1313
command: [/bin/echo]
1414
args: ["$(params.message)"]
15+
16+
---
17+
apiVersion: tekton.dev/v1beta1
18+
kind: Task
19+
metadata:
20+
name: cleanup
21+
spec:
22+
description: This task will clean up a workspace by deleting all of the files.
23+
workspaces:
24+
- name: source
25+
steps:
26+
- name: remove
27+
image: alpine:3
28+
env:
29+
- name: WORKSPACE_SOURCE_PATH
30+
value: $(workspaces.source.path)
31+
workingDir: $(workspaces.source.path)
32+
securityContext:
33+
runAsNonRoot: false
34+
runAsUser: 0
35+
script: |
36+
#!/usr/bin/env sh
37+
set -eu
38+
echo "Removing all files from ${WORKSPACE_SOURCE_PATH} ..."
39+
# Delete any existing contents of the directory if it exists.
40+
#
41+
# We don't just "rm -rf ${WORKSPACE_SOURCE_PATH}" because ${WORKSPACE_SOURCE_PATH} might be "/"
42+
# or the root of a mounted volume.
43+
if [ -d "${WORKSPACE_SOURCE_PATH}" ] ; then
44+
# Delete non-hidden files and directories
45+
rm -rf "${WORKSPACE_SOURCE_PATH:?}"/*
46+
# Delete files and directories starting with . but excluding ..
47+
rm -rf "${WORKSPACE_SOURCE_PATH}"/.[!.]*
48+
# Delete files and directories starting with .. plus any other character
49+
rm -rf "${WORKSPACE_SOURCE_PATH}"/..?*
50+
fi
51+
1552
---
1653
apiVersion: tekton.dev/v1beta1
1754
kind: Task

labs/06_deploy_to_kubernetes/pipeline.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ spec:
1111
- name: branch
1212
default: master
1313
tasks:
14+
- name: init
15+
workspaces:
16+
- name: source
17+
workspace: pipeline-workspace
18+
taskRef:
19+
name: cleanup
20+
1421
- name: clone
1522
workspaces:
1623
- name: output
@@ -22,6 +29,8 @@ spec:
2229
value: $(params.repo-url)
2330
- name: revision
2431
value: $(params.branch)
32+
runAfter:
33+
- init
2534

2635
- name: lint
2736
workspaces:

labs/06_deploy_to_kubernetes/tasks.yaml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,43 @@ spec:
1212
image: alpine:3
1313
command: [/bin/echo]
1414
args: ["$(params.message)"]
15+
16+
---
17+
apiVersion: tekton.dev/v1beta1
18+
kind: Task
19+
metadata:
20+
name: cleanup
21+
spec:
22+
description: This task will clean up a workspace by deleting all of the files.
23+
workspaces:
24+
- name: source
25+
steps:
26+
- name: remove
27+
image: alpine:3
28+
env:
29+
- name: WORKSPACE_SOURCE_PATH
30+
value: $(workspaces.source.path)
31+
workingDir: $(workspaces.source.path)
32+
securityContext:
33+
runAsNonRoot: false
34+
runAsUser: 0
35+
script: |
36+
#!/usr/bin/env sh
37+
set -eu
38+
echo "Removing all files from ${WORKSPACE_SOURCE_PATH} ..."
39+
# Delete any existing contents of the directory if it exists.
40+
#
41+
# We don't just "rm -rf ${WORKSPACE_SOURCE_PATH}" because ${WORKSPACE_SOURCE_PATH} might be "/"
42+
# or the root of a mounted volume.
43+
if [ -d "${WORKSPACE_SOURCE_PATH}" ] ; then
44+
# Delete non-hidden files and directories
45+
rm -rf "${WORKSPACE_SOURCE_PATH:?}"/*
46+
# Delete files and directories starting with . but excluding ..
47+
rm -rf "${WORKSPACE_SOURCE_PATH}"/.[!.]*
48+
# Delete files and directories starting with .. plus any other character
49+
rm -rf "${WORKSPACE_SOURCE_PATH}"/..?*
50+
fi
51+
1552
---
1653
apiVersion: tekton.dev/v1beta1
1754
kind: Task

0 commit comments

Comments
 (0)