2025-04-16 04:18:30 +00:00

39 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: context
description: |
The unique folder name created in the shared workspace.
workspaces:
- name: base
steps:
- name: create-folder
image: ubuntu
script: |
#!/bin/bash
context="$(params.workingFolderPrefix)-$(date +%s)-$(head /dev/urandom | tr -dc a-z0-9 | head -c 6)"
mkdir -p /workspace/base/${context}/source
mkdir -p /workspace/base/${context}/home
chmod -R a+rwX /workspace/base/${context}
echo "Created folder: ${context}/{source | home}"
echo -n "${context}" > $(results.context.path)