2025-04-15 11:35:19 +00:00

38 lines
1.4 KiB
YAML

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: workingFolderPrefix
type: string
default: "pipeline-run"
description: |
A prefix for the working folder name.
The final folder name will include this prefix, a timestamp, and a random string.
results:
- name: workingFolder
description: |
The unique folder name created in the shared workspace.
workspaces:
- name: shared
steps:
- name: create-folder
image: ubuntu
script: |
#!/bin/bash
workingFolder="$(params.workingFolderPrefix)-$(date +%s)-$(head /dev/urandom | tr -dc a-z0-9 | head -c 6)"
mkdir -p /workspace/shared/${workingFolder}
chmod -R a+rwX /workspace/shared/${workingFolder}
echo "Created folder: ${workingFolder}"
echo -n "${workingFolder}" > $(results.workingFolder.path)