Dynamic variables not working inside includes
- Task version: 3.37.2
- Operating system: MacOS
- Experiments enabled: TASK_X_MAP_VARIABLES=2
Taskfile:
version: '3'
vars:
ENV_NAME:
sh: echo $(hostname)_$(users)
includes:
test_import:
taskfile: '{{.ENV_NAME}}.yml'
tasks:
test:
cmds:
- echo {{.ENV_NAME}}
This will fail with:
stat /path/to/my/workspace/.yml: no such file or directory
It seems that ENV_NAME evaluates to an empty string inside test_import.
This won't work either:
version: '3'
dotenv:
- .env
includes:
test_import:
taskfile: '{{.ENV_NAME}}.yml'
tasks:
test:
cmds:
- echo {{.ENV_NAME}}
where .env file contains:
ENV_NAME=my_env
I see similar behaviour with the special variables too
❯ ll
total 8.0K
-rw-r--r-- 1 chris chris 285 Jul 2 23:05 LocalTaskfile.yml
-rw-r--r-- 1 chris chris 176 Jul 2 23:06 Taskfile.yml
❯ cat Taskfile.yml
# yaml-language-server: $schema=https://taskfile.dev/schema.json
version: '3'
includes:
local:
taskfile: "{{.USER_WORKING_DIR}}/LocalTaskfile.yml"
# optional: true
❯ task --list-all
stat /LocalTaskfile.yml: no such file or directory
Task version: v3.38.0 (h1:O7kgA6BfwktXHPrheByQO46p3teKtRuq1EpGnFxNzbo=) Operating system: "Ubuntu 22.04.4 LTS (on WSL2) Experiments enabled: N/A
Indeed dynamic variables and special variables are not evaluated before the include
Indeed dynamic variables and special variables are not evaluated before the include
@vmaerten – just curious, why was it designed to behave this way?