I want that by env variable (string) the varb_letter will get different data from my metadata.
here is what I tried to do.
Can u assist?
thanks!!!
varb_letter: (( env("LANDSCAPE") == 'a' ? asjson(.metadata.a) : env("LANDSCAPE") == 'b' ? asjson(.metadata.b) : env("LANDSCAPE") == 'c' ? asjson(.metadata.c) ))
metadata:
a:
b:
c:
env variable control on the variable data, I'm getting errors of wrong syntax
For this answer I assume you use Spiff++ as a templating engine.
There are a few issues:
a
need to be enclosed in double quotes, not single quotes, so the correct syntax is env("LANDSCAPE") == "a"
:
without a space in between (because that conflicts with default yaml syntax. So the correct syntax for, e.g., the second condition is :env("LANDSCAPE") == "b"
MCVE:
varb_letter: (( env("LANDSCAPE") == "a" ? asjson(.metadata.a) :env("LANDSCAPE") == "b" ? asjson(.metadata.b) :env("LANDSCAPE") == "c" ? asjson(.metadata.c) :false ))
metadata:
a: 1
b: 2
c: 3
Output of spiff++ merge
with LANDSCAPE=b
for example:
metadata:
a: 1
b: 2
c: 3
varb_letter: "2"