Skip to content

Inconsistent variable evaluation order in included taskfiles. #2058

@WinkelCode

Description

@WinkelCode

Project structure:

$ tree
.
├── Taskfile.yml
├── Taskfile_A.yml
└── Taskfile_B.yml
$ cat Taskfile.yml
version: "3"

includes:
  TaskfileA:
    taskfile: "./Taskfile_A.yml"
  TaskfileB:
    taskfile: "./Taskfile_B.yml"

tasks:
  default:
    cmds:
      - "echo {{ .VAR2 }}"
$ cat Taskfile_A.yml 
version: "3"

vars:
  VAR1: "value1"
$ cat Taskfile_B.yml 
version: "3"

vars:
  VAR2: "{{ .VAR1 }} plus value2"

Demonstrating the issue

$ task
task: [default] echo value1 plus value2
value1 plus value2
$ task
task: [default] echo  plus value2
plus value2
$ task
task: [default] echo value1 plus value2
value1 plus value2

The order in which the variables of included Taskfiles are evaluated is non-deterministic. This poses a hard-to-debug problem in cases where a variable references one in a different Taskfile.

Expected behavior would be that the variables are evaluated in the order in which the Taskfiles are included.

Version

$ task --version
Task version: 3.41.0 ()

Operating system

macOS Sequoia 15.3.1

Experiments Enabled

None


Similar issue involving the dotenv functionality: #1847

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