init
This commit is contained in:
parent
3ef2049145
commit
5c9fa9337f
@ -2,24 +2,35 @@ apiVersion: tekton.dev/v1
|
||||
kind: Task
|
||||
metadata:
|
||||
name: after-pipeline
|
||||
annotations:
|
||||
tekton.dev/pipelines.minVersion: "0.28.0"
|
||||
tekton.dev/categories: "Cleanup"
|
||||
tekton.dev/tags: "directory,workspace"
|
||||
tekton.dev/displayName: "Cleanup Working Folder in Shared Workspace"
|
||||
spec:
|
||||
description: |
|
||||
This task removes a previously created working folder in the shared workspace.
|
||||
It accepts the folder name as a parameter. If the folder exists, it will be deleted.
|
||||
If the folder name is not provided or the folder does not exist, the task will exit gracefully.
|
||||
params:
|
||||
- name: pvcName
|
||||
- name: workingFolder
|
||||
type: string
|
||||
default: ""
|
||||
description: |
|
||||
The name of the PVC to delete. If empty, no action will be taken.
|
||||
|
||||
The name of the folder in the shared workspace to delete.
|
||||
If empty, no cleanup action will be performed.
|
||||
workspaces:
|
||||
- name: shared
|
||||
steps:
|
||||
- name: maybe-delete-pvc
|
||||
image: bitnami/kubectl:latest
|
||||
- name: cleanup-folder
|
||||
image: ubuntu
|
||||
script: |
|
||||
#!/bin/sh
|
||||
set -e
|
||||
#!/bin/bash
|
||||
|
||||
if [ -n "$(params.pvcName)" ]; then
|
||||
echo "🔧 Deleting PVC: $(params.pvcName)"
|
||||
kubectl delete pvc $(params.pvcName) || echo "⚠️ PVC not found: $(params.pvcName)"
|
||||
workingFolder="/workspace/shared/$(params.workingFolder)"
|
||||
if [ -d "${workingFolder}" ]; then
|
||||
rm -rf "${workingFolder}"
|
||||
echo "Deleted folder: ${workingFolder}"
|
||||
else
|
||||
echo "✅ No PVC to delete (pvcName is empty)"
|
||||
echo "Folder not found: ${workingFolder}"
|
||||
fi
|
||||
|
@ -2,62 +2,35 @@ apiVersion: tekton.dev/v1
|
||||
kind: Task
|
||||
metadata:
|
||||
name: before-pipeline
|
||||
annotations:
|
||||
tekton.dev/pipelines.minVersion: "0.28.0"
|
||||
tekton.dev/categories: "Preparation"
|
||||
tekton.dev/tags: "directory,workspace"
|
||||
tekton.dev/displayName: "Create Working Folder in Shared Workspace"
|
||||
spec:
|
||||
description: |
|
||||
This task generates a unique working folder inside the provided shared workspace.
|
||||
The folder name is a combination of the given prefix, a timestamp, and a random string.
|
||||
The result can be used as a scoped working directory for subsequent tasks in a pipeline.
|
||||
params:
|
||||
- name: pvcEnable
|
||||
- name: workingFolderPrefix
|
||||
type: string
|
||||
default: "false"
|
||||
default: "pipeline-run"
|
||||
description: |
|
||||
Whether to create a PersistentVolumeClaim (PVC).
|
||||
Set to "true" to create a PVC. Set to "false" to skip creation.
|
||||
- name: pvcSize
|
||||
type: string
|
||||
default: "1Gi"
|
||||
description: |
|
||||
The requested size of the PVC (e.g., "1Gi", "5Gi").
|
||||
- name: pvcStorageClass
|
||||
type: string
|
||||
default: ""
|
||||
description: |
|
||||
The name of the StorageClass to use. Leave empty to use the default storage class.
|
||||
A prefix for the working folder name.
|
||||
The final folder name will include this prefix, a timestamp, and a random string.
|
||||
results:
|
||||
- name: pvcName
|
||||
- name: workingFolder
|
||||
description: |
|
||||
The name of the created PVC. If pvcEnable is false, this will be an empty string.
|
||||
The unique folder name created in the shared workspace.
|
||||
workspaces:
|
||||
- name: shared
|
||||
steps:
|
||||
- name: maybe-create-pvc
|
||||
image: bitnami/kubectl:latest
|
||||
- name: create-folder
|
||||
image: ubuntu
|
||||
script: |
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
if [ "$(params.pvcEnable)" = "true" ]; then
|
||||
RAND=$(head /dev/urandom | tr -dc a-z0-9 | head -c 6)
|
||||
PVC_NAME="before-pvc-${RAND}"
|
||||
echo "Creating PVC: ${PVC_NAME}"
|
||||
|
||||
cat <<EOF > /tmp/pvc.yaml
|
||||
apiVersion: v1
|
||||
kind: PersistentVolumeClaim
|
||||
metadata:
|
||||
name: ${PVC_NAME}
|
||||
spec:
|
||||
accessModes:
|
||||
- ReadWriteOnce
|
||||
resources:
|
||||
requests:
|
||||
storage: $(params.pvcSize)
|
||||
volumeMode: Filesystem
|
||||
EOF
|
||||
|
||||
if [ "$(params.pvcStorageClass)" != "" ]; then
|
||||
echo " storageClassName: $(params.pvcStorageClass)" >> /tmp/pvc.yaml
|
||||
fi
|
||||
|
||||
kubectl apply -f /tmp/pvc.yaml
|
||||
echo -n "${PVC_NAME}" > $(results.pvcName.path)
|
||||
echo "PVC created: ${PVC_NAME}"
|
||||
else
|
||||
echo "PVC creation skipped (pvcEnable=false)"
|
||||
echo -n "" > $(results.pvcName.path)
|
||||
fi
|
||||
#!/bin/bash
|
||||
workingFolder="$(params.workingFolderPrefix)-$(date +%s)-$(head /dev/urandom | tr -dc a-z0-9 | head -c 6)"
|
||||
mkdir -p /workspace/shared/${workingFolder}
|
||||
echo "Created folder: ${workingFolder}"
|
||||
echo -n "${workingFolder}" > $(results.workingFolder.path)
|
||||
|
Loading…
x
Reference in New Issue
Block a user