You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
{{ env "NAME" }} template function returns empty for dotenv-injected variables, but works for shell-provided ones #3048
First of all, I'd like to say thank you for creating such a neat task runner! It really is a pleasure to use.
I recently discovered a small inconsistency that I can't make a sense of. I've searched through the open issues (e.g. #2807), but couldn't find anything related. My apologies if this was already brought up somewhere else.
Description
When an environment variable is provided to the tasks from the shell, the {{ env "NAME" }} template function resolves it correctly in the task-level vars. However, when the same variable is loaded from a dotenv file, the injected variable resolves in cmds and in dynamic sh: vars, but {{ env "NAME" }} evaluates to an empty string.
Steps to reproduce
Given a Taskfile.yml:
version: "3"dotenv:
- .envtasks:
try-vars:
silent: truevars:
TOKEN_VAR:
sh: echo ${TOKEN}TOKEN_VAR_TEMPLATE: '{{ env "TOKEN" }}'cmds:
- echo "Token from env vars '${TOKEN}'"
- echo "Token from task vars '{{ .TOKEN_VAR }}'"
- echo "Token from env template '{{ .TOKEN_VAR_TEMPLATE }}'"
The {{ env ... }} template resolves correctly for a variable from the shell environment:
$ TOKEN=super-secure-stuff task try-vars
Token from env vars 'super-secure-stuff'
Token from task vars 'super-secure-stuff'
Token from env template 'super-secure-stuff'
The {{ env ... }} template does not resolve for a variable added via a dotenv file:
$ echo "TOKEN=super-secure-stuff" > .env && task try-vars
Token from env vars 'super-secure-stuff'
Token from task vars 'super-secure-stuff'
Token from env template ''
Expected behavior
I'd expect both cases to behave identically: {{ env "TOKEN" }} should return the value loaded from the dotenv file.
Actual behavior
{{ env "TOKEN" }} returns an empty string when TOKEN comes from a dotenv file, even though the same value is visible to command subprocesses (${TOKEN}) and to dynamic sh: vars.
This behavior feels inconsistent. The dotenv variables reach the environment in which sh: echo ${TOKEN} runs, but the template {{ env ... }} function does not see them.
Hello !
You can use {{.TOKEN}} here: TOKEN_VAR_TEMPLATE: '{{.TOKEN}}'
This works with both shell environment variables and your top-level dotenv file. The env function only reads Task’s process environment, which loading a dotenv file does not modify.
@vmaerten Thanks for the pointer! Regular variables should work for my use case. I was just caught by surprise by the env function behavior, but it makes sense now knowing the loading priority.
Activity
vmaerten commentedon Sep 26, 2026
Hello !
You can use
{{.TOKEN}}here:TOKEN_VAR_TEMPLATE: '{{.TOKEN}}'This works with both shell environment variables and your top-level dotenv file. The env function only reads Task’s process environment, which loading a dotenv file does not modify.
Diover commentedon Sep 28, 2026
@vmaerten Thanks for the pointer! Regular variables should work for my use case. I was just caught by surprise by the
envfunction behavior, but it makes sense now knowing the loading priority.