Skip to content

computed vars in dotenv paths #2826

@rpf3

Description

@rpf3

Description

When a dotenv path references a variable computed via sh, the template renders incorrectly — the variable appears empty, causing the resolved path to fall back to the task's working directory.

Expected behavior

{{.DOTENV}} resolves to the output of mktemp and the dotenv file at that path is loaded.

Actual behavior

{{.DOTENV}} renders to an empty string. The empty path is resolved against the task's working directory.

$ task
task: Failed to read env file ...: read /home/user/project: is a directory

Related issues

Workaround

Avoid dotenv entirely and source the file explicitly in each task that needs it:

cmds:
  - |
    set -a && source {{.DOTENV}} && set +a

Version

3.48.0

Operating system

Ubuntu 20.04

Experiments Enabled

No response

Example Taskfile

version: '3'

vars:
  DOTENV:
    sh: mktemp

tasks:
  default:
    dotenv:
      - '{{.DOTENV}}'
    cmds:
      - echo "AWS_KEY=$AWS_KEY"

Metadata

Metadata

Assignees

No one assigned

    Labels

    state: needs triageWaiting to be triaged by a maintainer.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions