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

Define ENV vars not static #1630

Closed
wburningham opened this issue May 1, 2024 · 3 comments
Closed

Define ENV vars not static #1630

wburningham opened this issue May 1, 2024 · 3 comments

Comments

@wburningham
Copy link

Given the current taskfile:

version: 3

tasks:
  default:
    env:
      EFOO: "little env foo"
      EBAR: "little env bar"
    vars:
      VFOO: "little var foo"
      VBAR: "little var bar"
    cmds:
      - cmd: echo $EFOO
      - cmd: echo $EBAR
      - cmd: echo {{.VFOO}}
      - cmd: echo {{.VBAR}}

With the given invocation:

EBAR="BIG ENV BAR" VBAR="BIG VAR BAR" task

Outputs:

task: [default] echo $EFOO
little env foo
task: [default] echo $EBAR
BIG ENV BAR
task: [default] echo little var foo
little var foo
task: [default] echo little var bar
little var bar

Since the ENV defined in the taskfile are static AND they are not using the {{ default ...}} pattern I would expect that all output says "little...". Am I mistaken? Also shouldn't vars and env behave the same?

Thanks for clarifying this case.

  • Task version: v3.36.0 (h1:XVJ5hQ5hdzTAulHpAGzbUMUuYr9MUOEQFOFazI3hUsY=)
  • Operating system: macOS 14.4.1
  • Experiments enabled: remote taskfiles (but it should not affect this case)
@task-bot task-bot added the state: needs triage Waiting to be triaged by a maintainer. label May 1, 2024
@vmaerten
Copy link
Member

vmaerten commented May 1, 2024

Hello !
I think it's related to :

Env variable from the shell takes precedence over env defined in the Taskfile.

@wburningham
Copy link
Author

Thanks for the link. It looks like the issue I just created is a duplicate. I'm going to close this issue.

@task-bot task-bot removed the state: needs triage Waiting to be triaged by a maintainer. label May 1, 2024
@vmaerten
Copy link
Member

vmaerten commented May 1, 2024

Even if it won't resolve your issue but you can use templating system and default pipe, and you can also define dynamic env variable like this :

version: 3

tasks:
  default:
    env:
        EBAR: "big env bar"
        EBAZ:
          sh: echo "big env baz"
    vars:
      VFOO: "little var foo"
      VBAR: "little var bar"
    cmds:
      - cmd: echo {{.EFOO | default "little env foo"}}
      - cmd: echo $EBAR
      - cmd: echo $EBAZ
      - cmd: echo {{.VFOO}}
      - cmd: echo {{.VBAR}}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants