39 lines
1.0 KiB
YAML
39 lines
1.0 KiB
YAML
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)
|