Skip to content

Add option to ignore environment variables in Taskfile variable resolution #2221

@szpn

Description

@szpn

Description

We would like to propose adding an option to remove environment variables from the variable resolution precedence in Taskfiles.

Today, environment variables can unintentionally override Taskfile defaults, even when no value was explicitly passed.
This breaks predictability: a developer's local environment can silently affect task behavior, leading to hard-to-debug issues - especially in large teams.

Example context:
We use Taskfile in our monorepository to simplify development with easy-to-remember tasks.
Many tasks define user-optional variables with default values, for example:

tasks:
  db:dump:search:
    vars:
        ...
        USER: '{{.USER | default "local"}}'
        ...
    cmds: ...

Developers typically run tasks like:

$ task db:dump:search USER=user123

or simply:

$ task db:dump:search

In the second case, we expect the default value local to be used.
However, if the developer has a USER environment variable set on their machine, it overrides our intended default, even though the user did not pass anything.
This leads to confusing and unexpected task behavior.

Another real-world scenario:
Suppose a developer is troubleshooting something and temporarily sets a production AWS profile locally:

export AWS_PROFILE=prod

They run a few manual AWS CLI commands - but then forget about the export.
Later, they run a Task that's meant to safely connect to staging by default:

tasks:
  aws:exec:
    vars:
      AWS_PROFILE: '{{.AWS_PROFILE | default "staging"}}'
    cmds: ...

Running:

$ task aws:exec

unexpectedly connects to production, because the AWS_PROFILE environment variable silently overrides the Taskfile's intended safe default (staging).
This could lead to serious operational mistakes - like modifying production infrastructure when the developer thought they were working against staging.

Currently, Task resolves variables in this order (highest priority first):

  1. Variables declared directly in the task definition
  2. Variables passed when calling a task from another task
  3. Variables from the included Taskfile (for included tasks)
  4. Variables from the inclusion of the Taskfile
  5. Global variables (defined in vars: section)
  6. Environment variables

There is no way to opt-out of the environment fallback.

Proposal:
Introduce a setting (global or per-variable) to disable environment variable fallback during variable resolution.
This would ensure that developer-provided arguments and Taskfile defaults are always respected first - making task behavior fully predictable, safer, and environment-independent.

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