-
-
Notifications
You must be signed in to change notification settings - Fork 763
Description
Description
The docs specify this ordering:
Variables can be set in many places in a Taskfile. When executing templates, Task will look for variables in the order listed below (most important first):
- Variables declared in the task definition
- Variables given while calling a task from another (See Calling another task above)
- Variables of the included Taskfile (when the task is included)
- Variables of the inclusion of the Taskfile (when the task is included)
- Global variables (those declared in the vars: option in the Taskfile)
- Environment variables
Despite the fact that Environment variables are listed with the lowest priority in the docs, it seems that they are taking the highest priority over Variables declared in the task definition and Variables given while calling a task from another.
It seems like the templating within the env block has a completely different ordering, which is not shown in the docs.
This is making it difficult for me to define tasks with a static set of variables that are not overridden by the local environment. I want to do this so I can have tasks which perform operations on a specific cluster, even when run in a local env which has envvars or dotfiles pointing to a different cluster.
Version
v3.38.0
Operating system
Linux
Experiments Enabled
No response
Example Taskfile
version: "3.38.0"
tasks:
foo:
requires:
vars:
- FOO
env:
FOO: "{{.FOO}}"
cmd: echo $FOO
bar:
cmd:
task: foo
vars:
FOO: bar
baz:
vars:
FOO: foo
env:
FOO: "{{.FOO}}"
cmd: echo ${FOO}Example Outputs
Without an env vars set, I see:
$ task foo
task: Task "foo" cancelled because it is missing required variables: FOO
$ task bar
task: [foo] echo $FOO
bar
$ task baz
task: [baz] echo ${FOO}
fooWith an env var set, I see:
$ FOO=moo task foo
task: [foo] echo $FOO
moo
$ FOO=moo task bar
task: [foo] echo $FOO
moo
$ FOO=moo task baz
task: [baz] echo ${FOO}
moo