T
Task7d ago
Explorer

In included file, cannot set task dir with a variable containing absolute path

I often set the dir of a task through a variable, as shown at multiple places in the docs, e.g. at: https://taskfile.dev/usage/#looping-over-your-tasks-sources. However, for included files, this works not correctly if the path is absolute. For included files, it seems to be impossible to set the dir to an absolute path using a variable. root file: Taskfile.yaml
version: "3"

includes:
incl:
taskfile: ./Taskfile-incl.yaml

tasks:
no-dir:
cmd: "echo dir: not set, pwd: $(pwd)"

dir-as-string:
dir: "/tmp"
cmd: "echo dir: /tmp, pwd: $(pwd)"

dir-via-var:
vars:
FOLDER: "/tmp"
dir: "{{.FOLDER}}"
cmd: "echo dir: /tmp, pwd: $(pwd)"
version: "3"

includes:
incl:
taskfile: ./Taskfile-incl.yaml

tasks:
no-dir:
cmd: "echo dir: not set, pwd: $(pwd)"

dir-as-string:
dir: "/tmp"
cmd: "echo dir: /tmp, pwd: $(pwd)"

dir-via-var:
vars:
FOLDER: "/tmp"
dir: "{{.FOLDER}}"
cmd: "echo dir: /tmp, pwd: $(pwd)"
included file: Taskfile-incl.yaml
version: "3"

tasks:
no-dir:
cmd: "echo dir: not set, pwd: $(pwd)"

dir-as-string:
dir: "/tmp"
cmd: "echo dir: /tmp, pwd: $(pwd)"

dir-via-var:
vars:
FOLDER: "/tmp"
dir: "{{.FOLDER}}"
cmd: "echo dir: /tmp, pwd: $(pwd)"
version: "3"

tasks:
no-dir:
cmd: "echo dir: not set, pwd: $(pwd)"

dir-as-string:
dir: "/tmp"
cmd: "echo dir: /tmp, pwd: $(pwd)"

dir-via-var:
vars:
FOLDER: "/tmp"
dir: "{{.FOLDER}}"
cmd: "echo dir: /tmp, pwd: $(pwd)"
Running this gives the following. See attached screenshot as well.
xxxxx@dev:~/tasktest$ pwd
/home/xxxxx/tasktest
xxxxx@dev:~/tasktest$ task no-dir dir-as-string dir-via-var incl:no-dir incl:dir-as-string incl:dir-via-var
task: [no-dir] echo dir: not set, pwd: $(pwd)
dir: not set, pwd: /home/xxxxx/tasktest
task: [dir-as-string] echo dir: /tmp, pwd: $(pwd)
dir: /tmp, pwd: /tmp
task: [dir-via-var] echo dir: /tmp, pwd: $(pwd)
dir: /tmp, pwd: /tmp
task: [incl:no-dir] echo dir: not set, pwd: $(pwd)
dir: not set, pwd: /home/xxxxx/tasktest
task: [incl:dir-as-string] echo dir: /tmp, pwd: $(pwd)
dir: /tmp, pwd: /tmp
task: [incl:dir-via-var] echo dir: /tmp, pwd: $(pwd)
dir: /tmp, pwd: /home/xxxxx/tasktest/tmp
xxxxx@dev:~/tasktest$ pwd
/home/xxxxx/tasktest
xxxxx@dev:~/tasktest$ task no-dir dir-as-string dir-via-var incl:no-dir incl:dir-as-string incl:dir-via-var
task: [no-dir] echo dir: not set, pwd: $(pwd)
dir: not set, pwd: /home/xxxxx/tasktest
task: [dir-as-string] echo dir: /tmp, pwd: $(pwd)
dir: /tmp, pwd: /tmp
task: [dir-via-var] echo dir: /tmp, pwd: $(pwd)
dir: /tmp, pwd: /tmp
task: [incl:no-dir] echo dir: not set, pwd: $(pwd)
dir: not set, pwd: /home/xxxxx/tasktest
task: [incl:dir-as-string] echo dir: /tmp, pwd: $(pwd)
dir: /tmp, pwd: /tmp
task: [incl:dir-via-var] echo dir: /tmp, pwd: $(pwd)
dir: /tmp, pwd: /home/xxxxx/tasktest/tmp
No description
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?