Skip to content

Variable passed to an included taskfile task doesn't take precedence #2218

@szpn

Description

@szpn

Description

Hey, I came across an issue when using Taskfile,

Given the following file structure:

/
├── test
│   └── Taskfile.yml
└── Taskfile.yml

Taskfile contents:

/test/Taskfile.yml

version: "3"

includes:
  global:
    taskfile: ../Taskfile.yml
    dir: ../
    flatten: true

/Taskfile.yml

version: "3"

vars:
  USER: 'szpn'

tasks:
  test:
    cmd: |
      echo "Hello, USER: {{.USER}}"

Expected Behavior:

Running the task without passing USER works as expected from both / and /test directories - it uses the globally set variable USER: 'szpn':

/ $ task test
task: [test] echo "Hello, USER: szpn"

Hello, USER: szpn
/test/ $ task test
task: [test] echo "Hello, USER: szpn"

Hello, USER: szpn

When passing a USER parameter, it should take precedence over the global variable, regardless of which directory the command is run from:

/ $ task test USER=my_user
task: [test] echo "Hello, USER: my_user"

Hello, USER: my_user
/test/ $ task test USER=my_user
task: [test] echo "Hello, USER: my_user"

Hello, USER: my_user

Actual Behavior:

Passing USER=my_user only works correctly when running from the root (/).
When running from /test, the USER parameter is ignored, and the globa variable USER: 'szpn' is used:

/test/ $ task test USER=my_user
task: [test] echo "Hello, USER: szpn"

Hello, USER: szpn

Version

3.42.1

Operating system

macOS 15.0.1

Experiments Enabled

None

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions