Description
Overview
I have a three level Taskfile inclusion hierarchy. When setting a variable in a "middle-level" task file and executing a task in the third level, the TASKFILE_DIR value only evaluates to the third level.
I've searched and see a number of issues related to variable resolution and even tried to grok a couple of the open issues but I'm not sure if this is captured from this angle so just in case I'm doing it here. Feel free to delete if this is just noise. Or, if it will be "fixed" (maybe too strong a term) in an upcoming release please let me know.
Details
TASKFILE_DIR used in a task file doesn't seem to be evaluated at the time/scope the file is included, but rather at the time that the final task, however deep in include levels a task is run.
I'll show the files below. To illustrate the problem I run:
task level1:level2:print-test
and I get the following output:
TEST_ROOT = /tmp/root/level1/level2
VTEST_ROOT = /tmp/root/level1/level2
TEST_LEVEL1 = /tmp/root/level1/level2
VTEST_LEVEL1 = /tmp/root/level1/level2
TEST_LEVEL2 = /tmp/root/level1/level2
VTEST_LEVEL2 = /tmp/root/level1/level2
When, at least the way I read the docs and also the way I would expect it to work, the output should be:
TEST_ROOT = /tmp/root
VTEST_ROOT = /tmp/root
TEST_LEVEL1 = /tmp/root/level1
VTEST_LEVEL1 = /tmp/root/level1
TEST_LEVEL2 = /tmp/root/level1/level2
VTEST_LEVEL2 = /tmp/root/level1/level2
Layout
./tmp/root
├── Taskfile.yaml
└── level1/
├── Taskfile.yaml
└── level2/
├── Taskfile.yaml
Version
3.53.1
Operating system
Ubuntu 24.04
Experiments Enabled
No response
Example Taskfile
---
# /tmp/root/Taskfile.yml
version: '3'
env:
TEST_ROOT: '{{.TASKFILE_DIR}}'
vars:
VTEST_ROOT: '{{.TASKFILE_DIR}}'
includes:
level1:
taskfile: level1/Taskfile.yml
dir: level1
tasks:
print-test:
desc: root level
silent: true
cmds:
- 'echo TEST_ROOT:{{.TEST_ROOT}}'
- 'echo VTEST_ROOT:{{.VTEST_ROOT}}'
---
# /tmp/root/level1/Taskfile.yml
version: '3'
env:
TEST_LEVEL1: '{{.TASKFILE_DIR}}'
vars:
VTEST_LEVEL1: '{{.TASKFILE_DIR}}'
includes:
level2:
taskfile: level2/Taskfile.yml
dir: level2
tasks:
print-test:
desc: level1
silent: true
cmds:
- 'echo TEST_ROOT = {{.TEST_ROOT}}'
- 'echo VTEST_ROOT = {{.VTEST_ROOT}}'
- 'echo TEST_LEVEL1 = {{.TEST_LEVEL1}}'
- 'echo VTEST_LEVEL1 = {{.VTEST_LEVEL1}}'
---
# /tmp/root/level1/level2/Taskfile.yml
version: '3'
env:
TEST_LEVEL2: '{{.TASKFILE_DIR}}'
vars:
VTEST_LEVEL2: '{{.TASKFILE_DIR}}'
tasks:
print-test:
desc: level2
silent: true
cmds:
- 'echo TEST_ROOT = {{.TEST_ROOT}}'
- 'echo VTEST_ROOT = {{.VTEST_ROOT}}'
- 'echo TEST_LEVEL1 = {{.TEST_LEVEL1}}'
- 'echo VTEST_LEVEL1 = {{.VTEST_LEVEL1}}'
- 'echo TEST_LEVEL2 = {{.TEST_LEVEL2}}'
- 'echo VTEST_LEVEL2 = {{.VTEST_LEVEL2}}'
Description
Overview
I have a three level Taskfile inclusion hierarchy. When setting a variable in a "middle-level" task file and executing a task in the third level, the TASKFILE_DIR value only evaluates to the third level.
I've searched and see a number of issues related to variable resolution and even tried to grok a couple of the open issues but I'm not sure if this is captured from this angle so just in case I'm doing it here. Feel free to delete if this is just noise. Or, if it will be "fixed" (maybe too strong a term) in an upcoming release please let me know.
Details
TASKFILE_DIR used in a task file doesn't seem to be evaluated at the time/scope the file is included, but rather at the time that the final task, however deep in include levels a task is run.
I'll show the files below. To illustrate the problem I run:
task level1:level2:print-testand I get the following output:
When, at least the way I read the docs and also the way I would expect it to work, the output should be:
Layout
Version
3.53.1
Operating system
Ubuntu 24.04
Experiments Enabled
No response
Example Taskfile