Skip to content

Included Taskfiles have wrong working directory with USER_WORKING_DIR #1250

@idelchi

Description

@idelchi

I am having trouble executing tasks from an included file in the current working directory while using Taskfile.yml.

My goal is to be able to navigate to any sub-folder, run a task command, which would use the Taskfile.yml at the root, which in turn includes utilities and commands from other folders.

Here's a minimal example:

Taskfile.yml:

version: '3'

includes:
  info:
    taskfile: 'subfolder/Taskfile.yml'
    # dir: '{{.USER_WORKING_DIR}}

tasks:
  default: 
    cmds:
      - echo {{.USER_WORKING_DIR}}
      - pwd

subfolder/Taskfile.info.yml:

version: '3'

tasks:
  default: 
    cmds:
      - echo {{.USER_WORKING_DIR}}
      - pwd
    # dir: '{{.USER_WORKING_DIR}}'


When I'm inside the subfolder and run task info, the output is (as expected):

/home/user/ws/subfolder
/home/user/ws

Adding dir: '{{.USER_WORKING_DIR}}' to the include statement in Taskfile.yml, has no effect, while I would have expected it to resolve to /home/user/ws/subfolder.

Adding dir: '{{.USER_WORKING_DIR}}' to the task in subfolder/Taskfile.info.yml yields:

/home/user/ws/subfolder
/home/user/ws/home/user/ws/subfolder   (?)

It seems that USER_WORKING_DIR resolves to the correct directory, but the commands are not running there. Perhaps I'm using the functionality incorrectly?

A use-case is where I'm using the "--global" flag and have the aforementioned structure in my $HOME folder.
I can only get tasks in the 'root' Taskfile to execute in the current working context, but not the included ones.

  • Task version: v3.26.0
  • Operating system: Linux / Debian Bookworm
  • Experiments enabled: No

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions