T
Task3w ago
Nargit

Are variable unique across all imports ?

Hello, I notice that if 2 task have the same global variable but are imported from 2 different file, the resolution of variable is random.
# https://taskfile.dev

version: '3'

includes:
bar: Taskfile.bar.yaml
foo: Taskfile.foo.yaml

tasks:
default: # this does not matter
cmds:
- echo "hello"
silent: true
# https://taskfile.dev

version: '3'

includes:
bar: Taskfile.bar.yaml
foo: Taskfile.foo.yaml

tasks:
default: # this does not matter
cmds:
- echo "hello"
silent: true
version: '3'

vars:
NAME: "bar"

tasks:
default:
cmds:
- echo "{{.NAME}}"
silent: true
version: '3'

vars:
NAME: "bar"

tasks:
default:
cmds:
- echo "{{.NAME}}"
silent: true
version: '3'

vars:
NAME: "foo"

tasks:
default:
cmds:
- echo "{{.NAME}}"
silent: true
version: '3'

vars:
NAME: "foo"

tasks:
default:
cmds:
- echo "{{.NAME}}"
silent: true
Execute watch -c 'task foo'
I am expecting foo but the result of .NAME is random, either foo or barit's not deterministic.
Is this expected or a bug ?
2 Replies
vmaerten
vmaerten3w ago
Hello ! Indeed variables are global. We have discussions about changing this in the next major version. (You can follow : https://github.com/go-task/task/issues/2034 / https://github.com/go-task/task/issues/1030 / https://github.com/go-task/task/issues/1030)
Nargit
NargitOP3w ago
thank you, this was so frustrating

Did you find this page helpful?