Skip to content

Global vars are reevaluated for each task #2003

@Chewie

Description

@Chewie

Description

With the following taskfile:

version: 3

vars:
  TIME: '{{ now }}'

tasks:
  main:
    cmds:
      - task: sub1
      - task: sub2

  sub1:
    cmds:
      - echo {{ .TIME }}

  sub2:
    cmds:
      - echo {{ .TIME }}

I'd expect the value to be the same for both tasks, but instead I get the following output:

task: [sub1] echo 2025-01-15 11:26:00.963791733 +0100 CET m=+0.035128847
2025-01-15 11:26:00.963791733 +0100 CET m=+0.035128847
task: [sub2] echo 2025-01-15 11:26:00.967687754 +0100 CET m=+0.039024858
2025-01-15 11:26:00.967687754 +0100 CET m=+0.039024858

This make it impossible to use that variable as e.g. a version tag for an artifact.

This behavior might be as intended, but there's no mention of that in the docs, and I see no way to make it be evaluated only once :(

Cheers!

Version

Task version: v3.40.0 (h1:1gKx+2UDz06Jtm0MBiN+EqVN87wWEyspuEze4LRGusk=)

Operating system

Linux

Experiments Enabled

No response

Example Taskfile

version: 3

vars:
  TIME: '{{ now }}'

tasks:
  main:
    cmds:
      - task: sub1
      - task: sub2

  sub1:
    cmds:
      - echo {{ .TIME }}

  sub2:
    cmds:
      - echo {{ .TIME }}

Metadata

Metadata

Assignees

No one assigned

    Labels

    state: needs triageWaiting to be triaged by a maintainer.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions