garden
garden copied to clipboard
can't grab element from array after using split() in string templating
This doesn't work with err: Invalid template string (${split("something.else", ".")[0]}): Unable to parse as valid template string.
kind: Module
name: test
description: test env string templating
type: exec
variables:
element: ${split("something.else", ".")[0]}
tasks:
- name: test
env:
TEST: ${var.element}
command: ["echo $TEST"]
This does work as expected (prints "else" to the console)
kind: Module
name: test
description: test env string templating
type: exec
variables:
arr: ${split("something.else", ".")}
tasks:
- name: test
env:
TEST: ${var.arr[1]}
command: ["echo $TEST"]
This is still a valid issue, wasn't fixed by #3057.
@hnicke encountered this last week on the Discord working around another issue
split(string((var.memory-mb * 0.9) / 2), '.')[0] -> Unable to parse as valid template string.
looking for a workaround? here's one that i use:
${slice(split("foo,bar,baz", ","), 0, 1)}
this resolves to "foo"
UPDATE
2023 June 22 16:48 GMT-4
After upgrading to 0.13.3 I found the above workaround inconsistent (validation errors in some fields but not others, ie io.k8s.api.core.v1.Container.command: got "array", expected "string"
). Here's the new workaround
${string(slice(split("foo,bar,baz", ","), 0, 1))}
This resolves to "foo"