Skip to content

Environment variables from shell takes precedence over task file definition #1038

@jaedle

Description

@jaedle

Hey 👋

I guess I have found a bug yesterday on task: It looks like previously defined environment variable are not overwritten by the definition within the task file.

Taskfile

version: '3'

silent: true

tasks:
  default:
    env:
      KEY: 'other'
    cmds:
      - echo "$KEY"

Expected

I would expect the environment variable of KEY to be overwritten whatever the outside environment looks like.

$ task
other
$ KEY=some task
other

Actual

The environment variable from the outside shell takes precedence over the variable defined within the taskfile.

$ task
other
$ KEY=some task
some

Os + Taskfile-version

$ cat /etc/lsb-release 
DISTRIB_ID=LinuxMint
DISTRIB_RELEASE=21.1
DISTRIB_CODENAME=vera
DISTRIB_DESCRIPTION="Linux Mint 21.1 Vera"
$ task --version
Task version: v3.21.0 (h1:pVGAGXxJ9Pk5mvjqv/CsdAD4ZIzNMjF+vrXMueM/WFk=)

Why is that problem?

  1. I have not found any reference to that behavior in the docs.
  2. I love to clearly define my environment when using task rather than relying on any other outer state. In that case it's impossible to overwrite previously defined variables which may be a huge issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    breaking changeChanges that are not backward compatible.status: stableExperimental feature - No more changes. Will be the default behavior in the next major release.
    No fields configured for experiment.

    Projects

    Status

    stable

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions