Skip to content

Version 3.42 breaks some variable usages inside go templates #2106

@vctls

Description

@vctls

Description

I have multiple taskfiles that use the following pattern to factorize global variables that are expensive to initialize:

version: "3"
vars:
  FOO:
    sh: |-
      echo {{ if .TASK | contains "bar"}}baz{{end}}
tasks:
  bar:
    cmd: echo {{.FOO}}

This worked fine in 3.41.0:

❯ task bar
task: [bar] echo baz
baz

Now in version 3.42, I get the following error:

❯ task bar
template: :1:28: executing "" at <"bar">: invalid value; expected string

Which suggests that the TASK variable is not a string.

But if I do this:

version: "3"
vars:
  FOO:
    sh: |-
      echo {{.TASK}}
tasks:
  bar:
    cmd: echo {{.FOO}}

…then the value of the variable is printed:

❯ task bar
task: [bar] echo bar
bar

Not sure what's going on here.
Maybe I'm using the variables in an unexpected way.

Version

3.42

Operating system

Ubuntu 22.04

Experiments Enabled

No response

Example Taskfile

version: "3"
vars:
  FOO:
    sh: |-
      echo {{ if .TASK | contains "bar"}}baz{{end}}
tasks:
  bar:
    cmd: echo {{.FOO}}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions