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
Sometimes my taskfiles and scripts they call require both vars and env to be set to the same values. You can imagine a cmd using a var {{.VAR}} and the script it calls (or envsubst) also using the same var but as env $VAR.
It would be great if there was a way to easily have env inherit vars set on a task.
TASK_X_MAP_VARIABLES=0 task test
err: maps cannot be assigned to variables
file: /tmp/Taskfile.yaml:8:11
6 | - echo "using vars {{.FOO}}"
7 | - echo "using env $FOO and $FIZZ"
> 8 | vars: &vars
| ^
9 | FOO: bar
10 | env:
TASK_X_MAP_VARIABLES=1 task test
task: [test] echo "using vars bar"
using vars bar
task: [test] echo "using env $FOO and $FIZZ"
using env and buzz
task: [test] cat test.txt | envsubst
:buzz
Purposed solution
Even if the above worked, it would still be great to have the below to avoid the anchor/alias jank.
version: '3'tasks:
test:
cmds:
- echo "using vars {{.FOO}}"
- echo "using env $FOO and $FIZZ"
- cat test.txt | envsubst # test.txt has content '$FOO:$FIZZ'vars:
FOO: barenvFromVars: true # assign all vars to envenv:
FIZZ: buzz # and also allow adding other env
Expected Output
task test
task: [test] echo "using vars bar"
using vars bar
task: [test] echo "using env $FOO and $FIZZ"
using env bar and buzz
task: [test] cat test.txt | envsubst
bar:buzz
Activity
[-]Option to easily assign env to vars[/-][+]Option to assign env to vars[/+][-]Option to assign env to vars[/-][+]Option to assign env from vars[/+]rfan-debug commentedon Mar 27, 2025
This is an important feature to structure Taskfile cleanly. Now we have to duplicate env vars almost in every sub command.
pd93 commentedon Mar 28, 2025
Added this to the variables megathread. Would be interesting to hear your thoughts on #2036.
trulede commentedon Dec 9, 2025
I don't know exactly why, but this is fixed by #2551.
I will close this as a duplicate, please try #2551 and comment there.