Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic variables not working inside includes #1690

Open
simonrouse9461 opened this issue Jun 12, 2024 · 4 comments
Open

Dynamic variables not working inside includes #1690

simonrouse9461 opened this issue Jun 12, 2024 · 4 comments
Labels
area: reader Changes related to the Taskfile reader.

Comments

@simonrouse9461
Copy link

  • 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.

@task-bot task-bot added the state: needs triage Waiting to be triaged by a maintainer. label Jun 12, 2024
@simonrouse9461
Copy link
Author

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

@cbrown1234
Copy link

cbrown1234 commented Jul 2, 2024

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

@vmaerten
Copy link
Member

vmaerten commented Jul 7, 2024

Indeed dynamic variables and special variables are not evaluated before the include

@vmaerten vmaerten added type: feature A new feature or functionality. area: reader Changes related to the Taskfile reader. and removed state: needs triage Waiting to be triaged by a maintainer. labels Jul 7, 2024
@pd93 pd93 removed the type: feature A new feature or functionality. label Dec 16, 2024
@kylejb
Copy link

kylejb commented Jan 30, 2025

Indeed dynamic variables and special variables are not evaluated before the include

@vmaerten – just curious, why was it designed to behave this way?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: reader Changes related to the Taskfile reader.
Projects
None yet
Development

No branches or pull requests

6 participants