Use --var flag for deploy command
# 🌱|help-and-getting-started
p
Hi, I want to define a namespace name dynamically. In my
project.garden.yml
I have :
Copy code
Yaml
variables:
  source-branch: ${lower(slice(camelCase(git.branch), 0, 32))}
environments:
  - name: preview
    defaultNamespace: pr-${var.source-branch}
When I run the command
garden deploy --env preview --var source-branch=2215
the namespace name uses the default variable, not the one defined in the command. What am I doing wrong? Thanks for your help
c
Hi @plain-pizza-51556. I did some investigation and it looks like this is indeed a bug. There must be something wrong with the order of resolving the templates when parsing the environment configuration. I tried a very similar setup and if you try to run
garden get config
you'll see, under the
variable
the correct value (passed via the CLI) but the
defaultNamespace
somehows seems to get the default one.
It would be very helpful if you could open a GitHub issue so we can assign it to someone.
In the meantime, I tested that this configuration works:
Copy code
variables:
  source-branch: ${local.env.SOURCE_BRANCH_OVERRIDE || lower(slice(camelCase(git.branch), 0, 32))}
environments:
  - name: preview
    defaultNamespace: pr-${var.source-branch}
And you could run something like:
Copy code
SOURCE_BRANCH_OVERRIDE=2215 garden deploy --env preview
instead.
Sorry for the inconvenience, I hope this helps until we get it fixed
p
Thanks @chilly-gigabyte-83853 for your help! I'm going to do this
c
Thank you so much! We'll take a look!
6 Views