Skip to content

Variable definitions are re-evaluated in deferred cmds #2244

@infogulch

Description

@infogulch

Description

It seems that every time a defer: command is run, variable templates are re-evaluated. This is problematic when using nondeterministic variable definitions that include things like the randInt builtin. In addition, this breaks from the behavior of normal commands where all executions seem to share the same variable values.

For example, I would expect the example task to print the same path value 4 times, but instead it prints 2 of the same path then 2 more different paths (a total of 3 unique paths).

Version

3.43.2

Operating system

Windows

Experiments Enabled

No response

Example Taskfile

tasks:
  test:
    vars:
      DIR: '{{.ROOT_DIR}}/temp-{{randInt 1000000 9999999}}'
    cmds:
      - echo "{{.DIR}}"
      - defer: echo "{{.DIR}}"
      - defer: echo "{{.DIR}}"
      - echo "{{.DIR}}"

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