Skip to content

potential bug: Variables in included files override ones in parent file #1800

@pbitty

Description

@pbitty

When I include a Taskfile that has env and vars that overlap the parent taskfile, the parent file's variables get overwritten at parent tasks' scope.

I am running task with the following files:

Taskfile.yml

version: '3'

includes:
  child: ./Taskfile.child.yml

env:
  ENV_VAR: root-file

vars:
  VAR: root-file

tasks:
  default: |
    echo ENV_VAR is $ENV_VAR
    echo VAR is {{ .VAR }}

Taskfile.child.yml

version: '3'

env:
  ENV_VAR: child-file

vars:
  VAR: child-file

# No tasks needed for this example.

Expected output:

ENV_VAR is root-file
VAR is root-file

Actual output:

ENV_VAR is child-file
VAR is child-file

I believe the code responsible is here:

t1.Vars.Merge(t2.Vars, include)
t1.Env.Merge(t2.Env, include)
, where merge the included file's variables into the parent.

Is this intentional behaviour? I would expect that the parent could provide defaults for the child, or override via include.*.vars, but it is surprising to have the child influence values on the parent.

If this is indeed a bug, I'd be happy to contribute a fix.

  • Task version: HEAD@114d5e1
  • Operating system: MacOS 14.4.1
  • Experiments enabled: None

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