This commit is contained in:
병준 박 2025-04-25 21:25:16 +00:00
parent 3cfa03cd45
commit 9c75a5cfb2

View File

@ -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)