Replies: 2 comments
-
|
Hey if you augment your example like this you will see something consistent with the document: .env: output: As you can see VAR_X does pick up the .env file defined variables. There is an experiment in the latest version that alters these orders, which in my opinion is dangerous. |
Beta Was this translation helpful? Give feedback.
-
|
I spent hours trying to debug why my tasks were falling back to defaults even for variables defined in my Here's what I found… If you're loading a variable through Here's an example: version: '3'
dotenv: ['.env'] # MY_VAR="DOTENV_VALUE"
# global-level env
env:
MY_VAR: '{{ .MY_VAR | default "FALLBACK_VALUE" }}'
tasks:
echo-my-var:
cmds:
- echo "MY_VAR:" "$MY_VAR"
# > task echo-my-var
# MY_VAR: FALLBACK_VALUEThat will output But if we move the version: '3'
dotenv: ['.env'] # MY_VAR="DOTENV_VALUE"
tasks:
echo-my-var:
# Task-level env
env:
MY_VAR: '{{ .MY_VAR | default "FALLBACK_VALUE" }}'
cmds:
- echo "MY_VAR:" "$MY_VAR"
# > task echo-my-var
# MY_VAR: DOTENV_VALUEThe Env Precedence experiment has no bearing on this behaviour. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Currently, if you have:
The
ENVvariable in this case is picked up from the command line or the valuedefault_envis used otherwise, this is great. However, ifVAR_Xis set within.envfile, then it is not picked up and the value will always be123due to thedefault; it would have to be set on the command line for it to be picked up.Setting on the command line should take precedence, I think, but otherwise loading from a dotenv file next would be great.
I think there might be a chicken-and-egg situation such that the env vars need to be evaluated in order to select the correct dotenv file but maybe after loading dotenv the env vars defined in the
env:section could be re-evaluated?Thanks for a great tool, finding it really useful so far!
Beta Was this translation helpful? Give feedback.
All reactions