task
task copied to clipboard
[BUG] Enable dotenv will make go template pipeline be invalid.
- Task version: v3.25.0 (h1:XtIEtWpQSbIf2FGU+44/QB1whFf2sBUB/02W7ZQSz0U=)
- Operating system: Windows 10
- Experiments enabled: false
How to reproduce it?
When I don't include dotenv key in config file, all things work well:
version: '3'
vars:
ROOT:
sh: echo {{toSlash .ROOT_DIR}}
DOCKER:
sh: echo {{.ROOT}}/docker
tasks:
foo:
cmds:
- echo {{.DOCKER}}
# in my directory: D:/Reops/test
$ task foo
task: [foo] echo D:/Repos/test/docker
D:/Repos/test/docker
But when I add dotenv keys in config file with an empty .env file(created but no content):
version: '3'
dotenv:
- .env
vars:
ROOT:
sh: echo {{toSlash .ROOT_DIR}}
DOCKER:
sh: echo {{.ROOT}}/docker
tasks:
foo:
cmds:
- echo {{.DOCKER}}
then run task again and the console will show:
$ task foo
template: :1:15: executing "" at <.ROOT_DIR>: invalid value; expected string
+1 Well it seems more like that all taskfile defined env is simply not substituted in dynamic vars.
env:
IMAGE_DIR: "HELLO"
# or
# dotenv: [".env"]
tasks:
mkdisk:
vars:
imageDir: '{{ env "IMAGE_DIR" }}'
cmds:
- echo '{{.imageDir}}'
This is also happening to me, the following doesn't work as well:
vars:
TEST: "{{.USER_WORKING_DIR | toSlash}}"
dotenv:
- ".env"
tasks:
test:
desc: "A test task"
cmds:
- echo 'This is a test!'
- Task version: v3.38.0 (h1:O7kgA6BfwktXHPrheByQO46p3teKtRuq1EpGnFxNzbo=)
- Operating System: Windows 11
- Experiments Enabled: no
This works as expected when defining vars at the task level:
dotenv:
- sandwich.env
vars:
SANDWICH: '{{ env "SANDWICH" | default .DEFAULT_SANDWICH }}.sandwich'
tasks:
sandwich:
vars:
SANDWICH_PATH: '{{ joinPath .ROOT_DIR .SANDWICH_DIR .SANDWICH | osClean }}'
cmds:
- echo {{ relPath .ROOT_DIR .SANDWICH_PATH | toSlash }}
$ task sandwich
task: [sandwich] echo sandwiches/cheese-and-pickle.sandwich
sandwiches/cheese-and-pickle.sandwich
It breaks when a template pipeline is used at the global var level:
dotenv:
- sandwich.env
vars:
SANDWICH: '{{ env "SANDWICH" | default .DEFAULT_SANDWICH }}.sandwich'
SANDWICH_PATH: '{{ joinPath .ROOT_DIR .SANDWICH_DIR .SANDWICH | osClean }}'
tasks:
sandwich:
cmds:
- echo {{ relPath .ROOT_DIR .SANDWICH_PATH | toSlash }}
$ task sandwich
template: :1:12: executing "" at <.ROOT_DIR>: invalid value; expected string
sandwich.env for reference:
SANDWICH_DIR=sandwiches
DEFAULT_SANDWICH=cheese-and-pickle