fresh-yak-35965
05/23/2024, 11:14 PMkind: Run
name: print-username
description: Print the local username
type: exec
spec:
command: ["sh", "-c", "echo 'The local username is: ${command.params.env}'"]
The above action works well! Output:
The local username is: jack.dev
Now this is broken:
kind: Run
name: print-username
description: Print the local username
type: exec
spec:
command: ["sh", "-c", "echo 'The local username is: ${split(command.params.env, '.')[0]}'"]
Invalid template string (echo 'The local username is: ${split(command.params.env, '.')[0]}') at path spec.command.2: Unable to parse as valid template string.
I remember bringing this up a couple of years ago and was returning to the workaround I had in place to see if I could fix it.fresh-yak-35965
05/23/2024, 11:21 PMcommand: ['sh', '-c', "echo '${split(command.params.env, \",\")}'"]
fresh-yak-35965
05/23/2024, 11:27 PMcommand: ['sh', '-c', "echo '${slice(split(command.params.env, \",\"), 0, 1)[0]}'"]
Also invalidcurved-intern-91221
05/28/2024, 11:48 AMsplit
function call to a standalone variable (e,g, result
), then you can use index-based access on that, it should work fine: result[0]
.
Please let us know if it works.fresh-yak-35965
06/04/2024, 1:09 PMfresh-yak-35965
06/05/2024, 1:42 PMyaml
kind: Project
apiVersion: garden.io/v1
name: kraken
defaultEnvironment: dev
scan:
exclude:
- "node_modules/**/*"
variables:
env: ${split(command.params.env, ".")}
environments:
- name: dev
production: false
defaultNamespace: dev-${local.env.CHANGE_ID || local.username}
variables:
mode: ${local.env.MODE || ""}
baseHostName: ${var.env[0]}.kraken.scalecomputing.dev
Unfortunately, I get a nonsense error about it failing to resolve project configuration (as in depicted), which isn't legitimate because it deploy --sync
subsequently works find with the properly resolved variable.
https://cdn.discordapp.com/attachments/1243341282236043294/1247908474751422588/image.png?ex=6661bcd5&is=66606b55&hm=224857a4df78bec676ff5c4eaa0699adef5afb3462d5093ec03c2eb6a403696b&fresh-yak-35965
06/05/2024, 1:44 PMgarden deploy --prefix jack
Or something. Maybe I can define this in a custom command.curved-intern-91221
06/06/2024, 12:30 PMkind: Project
apiVersion: garden.io/v1
name: kraken
defaultEnvironment: dev
scan:
exclude:
- "node_modules/**/*"
variables:
env: ${split(command.params.env, ".")}
environments:
- name: dev
production: false
defaultNamespace: dev-${local.env.CHANGE_ID || local.username}
variables:
mode: ${local.env.MODE || ""}
baseHostName: ${var.env[0]}.kraken.scalecomputing.dev
---
kind: Run
name: print-all
description: Print original input and variables
type: exec
spec:
command: ["sh", "-c", "echo 'The local username is: ${command.params.env};\nThe var.env is ${var.env};\nThe var.env[0] is ${var.env[0]};\nThe resolved value of enviromemnts.dev.variables.baseHostName is ${var.baseHostName}'"]
I executed
garden run print-all --env jack.dev --force-refresh
and the output was:
The local username is: jack.dev;
The var.env is jack,dev;
The var.env[0] is jack;
The resolved value of enviromemnts.dev.variables.baseHostName is jack.kraken.scalecomputing.dev
So, it worked well.
Could you please share the full config of your example and the exact command that you tried?curved-intern-91221
06/06/2024, 12:31 PMcurved-intern-91221
06/06/2024, 12:38 PM--env
option (i.ee. trying garden run print-all
), it fails as you mentioned above
Invalid template string (${split(command.params.env, ".")}) at path variables.env: Error validating argument 'string' for split helper function:
value must be a string
So, the error message is not that informative and user-friendly, it seems to be too low-level and technical. But the problem is that the template string resolution engine tries to resolve the non-existing value. We might need to improve that part by checking if the value is undefined
or null
before parsing it, and to print a meaninigful error. I'll create a ticket for that.curved-intern-91221
06/06/2024, 12:39 PM--env
option.curved-intern-91221
06/06/2024, 1:02 PMfresh-yak-35965
06/06/2024, 1:14 PM--env
when using garden dev
. So
garden dev --env jack.dev
Is the specific command that acted as if I hadn't passed the env flag, but then the deploy worked recognizing the arguments.curved-intern-91221
06/06/2024, 1:48 PMcurved-intern-91221
06/07/2024, 8:35 AMcurved-intern-91221
06/07/2024, 8:45 AMcurved-intern-91221
06/11/2024, 11:37 AMfresh-yak-35965
06/12/2024, 12:24 PM