Skip to content

Absolute path bug when using include and dir #2443

@roycamp

Description

@roycamp

Description

When setting an absolute directory (ex. /tmp) from a variable and using that in the dir: directive of an included taskfile, it is treated as a relative path. However, it is dependent on the syntax of the include. Minimal working example included below.

When included using this syntax, the variable is treated as a relative path:

vars:
  TARGET_DIR: '/tmp'
includes:
  broken: 
    taskfile: ./Taskfile.broken.yml

When used like this:

tasks:
  broken:
    dir: "{{.TARGET_DIR}}"
    cmds:
      - |
          echo "PWD DIR: $(pwd)" 

Version

3.45.4

Operating system

OSX 26

Experiments Enabled

No response

Example Taskfile

# Taskfile.yml
version: '3'

vars:
  TARGET_DIR: '/tmp'

includes:
  working: ./Taskfile.working.yml
  broken: 
    taskfile: ./Taskfile.broken.yml
    # this also doesn't fix it
    #vars:
    #  TARGET_DIR: "{{.TARGET_DIR}}"
tasks:
  default:
    cmds:
      - task: working:working
      - task: broken:broken
# Taskfile.working.yml
version: '3'

tasks:
  working:
    dir: "{{.TARGET_DIR}}"
    cmds:
      - |
          echo "TARGET_DIR: {{.TARGET_DIR}}"
          echo "PWD DIR: $(pwd)"          
          cd {{.TARGET_DIR}}
          echo "PWD AFTER CD: $(pwd)"
# Taskfile.broken.yml
version: '3'

tasks:
  broken:
    dir: "{{.TARGET_DIR}}"
    cmds:
      - |
          echo "TARGET_DIR: {{.TARGET_DIR}}"
          echo "PWD DIR: $(pwd)"          
          cd {{.TARGET_DIR}}
          echo "PWD AFTER CD: $(pwd)"

Metadata

Metadata

Assignees

No one assigned

    Labels

    state: needs triageWaiting to be triaged by a maintainer.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions