Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected variable scope behavior in included Taskfiles #2046

Closed
Shmillerov opened this issue Feb 7, 2025 · 1 comment
Closed

Unexpected variable scope behavior in included Taskfiles #2046

Shmillerov opened this issue Feb 7, 2025 · 1 comment

Comments

@Shmillerov
Copy link

Shmillerov commented Feb 7, 2025

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

@task-bot task-bot added the state: needs triage Waiting to be triaged by a maintainer. label Feb 7, 2025
@pd93
Copy link
Member

pd93 commented Feb 7, 2025

We recently opened a proposal to fix Taskfile scoping. This happens because we merge included Taskfiles together and the order is not deterministic.

As a workaround, you can use task-scoped variables. These should still behave as expected.

I have added a link back to this ticket in the proposal as an example, so we can check that it works when fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants