init
This commit is contained in:
parent
3cfa03cd45
commit
9c75a5cfb2
38
tasks/util-string-split/task.yaml
Normal file
38
tasks/util-string-split/task.yaml
Normal 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)
|
Loading…
x
Reference in New Issue
Block a user