Skip to content

Unexpected variable scope behavior in included Taskfiles #2046

@Shmillerov

Description

@Shmillerov

Description

Hello

I expected that variables declared in a taskfile have a scope only within the taskfile. But the example shows that it does not, and the behavior is not predictable.

It always prints the same value and this value is random selected:

➜  taskfile-test task included2:test
task: [included2:test] echo included2
included2
➜  taskfile-test task included2:test
task: [included2:test] echo included1
included1
➜  taskfile-test task -l
task: Available tasks for this project:
* included2:test:       Test task that prints included2
* included2:test:       Test task that prints included2
➜  taskfile-test task -l
task: Available tasks for this project:
* included1:test:       Test task that prints included1
* included2:test:       Test task that prints included1

I expect

➜  taskfile-test task included2:test
task: [included2:test] echo included2
included2
➜  taskfile-test task included1:test
task: [included1:test] echo included1
included1
➜  taskfile-test task -l
task: Available tasks for this project:
* included1:test:       Test task that prints included1
* included2:test:       Test task that prints included2

Taskfile structure

./Taskfile.yaml:

version: '3'

includes:
  included1: ./included1
  included2: ./included1

./included1/Taskfile.yaml:

version: '3'

vars:
  VARIABLE: included1

tasks:
  test:
    desc: Test task that prints {{.VARIABLE}}
    cmd: echo {{.VARIABLE}}

./included2/Taskfile.yaml:

version: '3'

vars:
  VARIABLE: included2

tasks:
  test:
    desc: Test task that prints {{.VARIABLE}}
    cmd: echo {{.VARIABLE}}

Version

v3.41.0

Operating system

MacOS 14.5

Experiments Enabled

No response

Example Taskfile

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions