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

Option to assign env from vars #1863

Open
onedr0p opened this issue Oct 13, 2024 · 0 comments
Open

Option to assign env from vars #1863

onedr0p opened this issue Oct 13, 2024 · 0 comments
Labels
state: needs triage Waiting to be triaged by a maintainer.

Comments

@onedr0p
Copy link
Contributor

onedr0p commented Oct 13, 2024

Hi 👋🏼

Sometimes my taskfiles and scripts they call require both vars and env to be set to the same values. You can imagine a cmd using a var {{.VAR}} and the script it calls (or envsubst) also using the same var but as env $VAR.

It would be great if there was a way to easily have env inherit vars set on a task.

Current issue

version: '3'

tasks:
  test:
    cmds:
      - echo "using vars {{.FOO}}"
      - echo "using env $FOO and $FIZZ"
      - cat test.txt | envsubst # test.txt has content '$FOO:$FIZZ'
    vars: &vars
      FOO: bar
    env:
      <<: *vars
      FIZZ: buzz

Output with various TASK_X_MAP_VARIABLES

TASK_X_MAP_VARIABLES=0 task test
err:  maps cannot be assigned to variables
file: /tmp/Taskfile.yaml:8:11
   6 |       - echo "using vars {{.FOO}}"
   7 |       - echo "using env $FOO and $FIZZ"
>  8 |     vars: &vars
     |           ^
   9 |       FOO: bar
  10 |     env:
TASK_X_MAP_VARIABLES=1 task test
task: [test] echo "using vars bar"
using vars bar
task: [test] echo "using env $FOO and $FIZZ"
using env  and buzz
task: [test] cat test.txt | envsubst
:buzz

Purposed solution

Even if the above worked, it would still be great to have the below to avoid the anchor/alias jank.

version: '3'

tasks:
  test:
    cmds:
      - echo "using vars {{.FOO}}"
      - echo "using env $FOO and $FIZZ"
      - cat test.txt | envsubst # test.txt has content '$FOO:$FIZZ'
    vars:
      FOO: bar
    envFromVars: true # assign all vars to env
    env:
      FIZZ: buzz # and also allow adding other env

Expected Output

task test
task: [test] echo "using vars bar"
using vars bar
task: [test] echo "using env $FOO and $FIZZ"
using env bar and buzz
task: [test] cat test.txt | envsubst
bar:buzz
@task-bot task-bot added the state: needs triage Waiting to be triaged by a maintainer. label Oct 13, 2024
@onedr0p onedr0p changed the title Option to easily assign env to vars Option to assign env to vars Oct 13, 2024
@onedr0p onedr0p changed the title Option to assign env to vars Option to assign env from vars Oct 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
state: needs triage Waiting to be triaged by a maintainer.
Projects
None yet
Development

No branches or pull requests

2 participants