Skip to content

Global vars can't use .CLI_ARGS special var as default value #2090

@angelmadames

Description

@angelmadames

Description

I wanted to use a global vars: key to default to the .CLI_ARGS special var.

vars:
  ENV: '{{.ENV | default .CLI_ARGS}}'

And then use it in a task, so both of these examples work:

task debug -- dev  # Should use 'dev' as value for `ENV`
task debug ENV=dev # Should behave similarly as `-- dev`

The above behavior works if vars: is used directly in the task definition:

tasks:
  debug:
    vars:
      ENV: '{{.ENV | default .CLI_ARGS}}'
    cmds:
      - echo '{{.ENV}}'

Only when using vars: globally .CLI_ARGS comes empty and doesn't work.

Version

v3.41.0 (h1:giUddhe0XZLbEWIQ/MuTPipR9ek+teulIA5xf/2IHXg=)

Operating system

macOS Sequioa 15.3.1 (24D70)

Experiments Enabled

No response

Example Taskfile

version: '3'

vars:
  ENV: '{{.ENV | default .CLI_ARGS}}'

tasks:
  debug:
    cmds:
      - echo '{{.ENV}}'

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