From 9c75a5cfb22e66fcece5f8becc6e7999997ea658 Mon Sep 17 00:00:00 2001 From: BAK BYEONG JUN Date: Fri, 25 Apr 2025 21:25:16 +0000 Subject: [PATCH] init --- tasks/util-string-split/task.yaml | 38 +++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 tasks/util-string-split/task.yaml diff --git a/tasks/util-string-split/task.yaml b/tasks/util-string-split/task.yaml new file mode 100644 index 0000000..d34490e --- /dev/null +++ b/tasks/util-string-split/task.yaml @@ -0,0 +1,38 @@ +apiVersion: tekton.dev/v1 +kind: Task +metadata: + name: util-string-split +spec: + description: | + Splits an input string by a given delimiter and returns the result as an array. + params: + - name: input + type: string + description: The string to split + - name: delimiter + type: string + description: The delimiter to split by + results: + - name: split + type: array + description: The resulting array after splitting + steps: + - name: split-string + image: python:3.9-slim + script: | + #!/usr/bin/env python3 + import os + input_str = os.environ["INPUT"] + delimiter = os.environ["DELIMITER"] + # Split and JSON-encode as array + arr = input_str.split(delimiter) + # Remove trailing newline if present + arr = [s.rstrip('\n') for s in arr] + with open("$(results.split.path)", "w") as f: + import json + json.dump(arr, f) + env: + - name: INPUT + value: $(params.input) + - name: DELIMITER + value: $(params.delimiter)