You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The result is my existing path. Switching from PATH to PATH2 shows test as expected. Is this intentional?
Reacted by Benjamin Führmann, Caleb Marshall, HY, Mark Phelps, Mikhail Lukianchenko, Sorin Sbarnea, Nokome Bentley, Marvin 马维 Drees, John Burbridge, Sunghoon Kang and 5 more
afaik, it is not possible to override environment variables, and this is expected. I asked in #449 whether it'd be possible to add this change in a PR, but the question hasn't been answered. I'd be happy to contribute with this but would like to know first if @andreynering would be open to have a PR with these changes.
Reacted by Maximilian Roos, Oleg Butuzov , Jacob McCollum, Marcello Sylvester Bauer and Caleb Marshall
Changing the priority order of ENVs is a breaking change and would be unexpected to existing users that rely on it. Currently it's possible to override ENVs with something like env MY_ENV=overriden task foo. This proposal would break that.
Making this change would make ENV work similar to VARS regarding its priority, but would require people to use MY_ENV: '{{default FOO .MY_ENV}}' on all ENV declarations that should be overridable. This could be inconvenient for some and would likely require a release of v4 since it's a breaking change. The same applies to #521.
I would love to hear opinions on what do you think. An alternative would likely be better than a breaking change. Let me know if you have any ideas on how to do that.
Regarding the ability to override PATH, as a workaround you could have a variable with the prefix command:
version: '3'vars:
PREFIX: env PATH="/some/path:$PATH"tasks:
foo:
cmds:
- '{{.PREFIX}} my command'
- '{{.PREFIX}} another command'
Perhaps #204 (comment) would be nice to have this workaround cleaner.
Reacted by Maximilian Roos, Marcello Sylvester Bauer, Wes McNamee, Ivo Jimenez, birros and John Burbridge
Which leads me to believe that really vars should be used more liberally than env, and env should always derive from vars, because then you can do this:
version: '3'vars:
HAM: '{{env "HAM"}}'tasks:
...
Which would allow the make behavior of HAM ?= default-value-here
It seems there are many related issues to this as well: #591, #658, #630, #593, #191
Have you considered adding an override_env variable in the global scope
which by default will be false (same order as now)
but if true, it will handle replacing existing envs (for example with PATH)
it would not be such a big change to increase the version to v4, but it also allowed to solve this problem
and in the future, simply version v4 will be the default value of true
Have you considered adding an override_env variable in the global scope which by default will be false (same order as now) but if true, it will handle replacing existing envs (for example with PATH)
it would not be such a big change to increase the version to v4, but it also allowed to solve this problem
A per-variable override (force, erase or whatever you see fit) parameter would be fine too. E.g.
Hi all, there are many open issues related to variables in v3. To help centralise and focus our discussions we have created a new megathread. The env precedence experiment is now stable and there are open tickets linked from the megathread to discuss inheritance and scoping so I'm going to close this issue.
Activity
ivotron commentedon May 3, 2021
afaik, it is not possible to override environment variables, and this is expected. I asked in #449 whether it'd be possible to add this change in a PR, but the question hasn't been answered. I'd be happy to contribute with this but would like to know first if @andreynering would be open to have a PR with these changes.
butuzov commentedon May 12, 2021
@ivotron Well you can try to implement this and maintain change at least in your fork. As for me will pull this change to mine for sure.
d3dc commentedon Jul 16, 2021
To me, it seems like the more correct way might be to opt-in to the inheritance.
I think the closest parallel would be a Dockerfile, where the stacking goes:
.envfile-eflagI think the interactions for most of this is underspecified. And the "$" in env: actually is equivalent to
{ sh: }.andreynering commentedon Jul 17, 2021
Hi everybody,
Changing the priority order of ENVs is a breaking change and would be unexpected to existing users that rely on it. Currently it's possible to override ENVs with something like
env MY_ENV=overriden task foo. This proposal would break that.Making this change would make ENV work similar to VARS regarding its priority, but would require people to use
MY_ENV: '{{default FOO .MY_ENV}}'on all ENV declarations that should be overridable. This could be inconvenient for some and would likely require a release of v4 since it's a breaking change. The same applies to #521.I would love to hear opinions on what do you think. An alternative would likely be better than a breaking change. Let me know if you have any ideas on how to do that.
Regarding the ability to override PATH, as a workaround you could have a variable with the prefix command:
Perhaps #204 (comment) would be nice to have this workaround cleaner.
ghostsquad commentedon Mar 1, 2022
I just found this, and this feels like a pretty big issue. Here's the simplest case:
I also tried this:
The following DOES work:
Which leads me to believe that really
varsshould be used more liberally thanenv, andenvshould always derive fromvars, because then you can do this:Which would allow the
makebehavior ofHAM ?= default-value-hereIt seems there are many related issues to this as well: #591, #658, #630, #593, #191
sirenkovladd commentedon Feb 14, 2024
@andreynering
Have you considered adding an
override_envvariable in the global scopewhich by default will be false (same order as now)
but if true, it will handle replacing existing envs (for example with PATH)
it would not be such a big change to increase the version to v4, but it also allowed to solve this problem
and in the future, simply version v4 will be the default value of true
Adirelle commentedon Nov 12, 2024
A per-variable
override(force,eraseor whatever you see fit) parameter would be fine too. E.g.mohsen1 commentedon Jan 10, 2025
This would be very useful to replace npm scripts with Task with simply doing
Currently I have to do:
pd93 commentedon Feb 3, 2025
Hi all, there are many open issues related to variables in v3. To help centralise and focus our discussions we have created a new megathread. The env precedence experiment is now stable and there are open tickets linked from the megathread to discuss inheritance and scoping so I'm going to close this issue.