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 variable execution environment does not inherit globally set environment variables #630

Open
kerma opened this issue Dec 17, 2021 · 4 comments
Assignees
Labels
area: variables Changes related to variables.

Comments

@kerma
Copy link
Contributor

kerma commented Dec 17, 2021

It may be as designed, but it's been bugging me for a while and creates quite a bit of confusion. So if nothing else, I'll document the behavior here.

See the following example:

version: '3'
env:
  NAME: "giselle"
tasks:
  default:
    vars: 
      person:
        sh: echo $NAME
    cmds:
      - echo "Hello $NAME"
      - echo "Hello {{ .person }}"
    silent: true

Output:

Hello giselle
Hello

That makes dynamic variables a bit useless in places where you need to pass auth or other relevant info via env.

@andreynering andreynering added type: bug Something not working as intended. area: variables Changes related to variables. labels Dec 20, 2021
@andreynering
Copy link
Member

Hi @kerma,

Good catch! I think it makes sense to fix this and make it consistent.

It may not be extremely easy, though. The variables pipeline is a separate process than the actual execution.

@kerma
Copy link
Contributor Author

kerma commented Dec 20, 2021

I'll do some investigation myself to figure out the complexity of it.

@megakoresh
Copy link

megakoresh commented Jan 19, 2024

This issue seems to have been abandoned but the inconsistent behavior is still there. Can this be given higher priority? What's the situation with complexity, @kerma ?

Additionally, when working around this with a environment variable defaults, it does not work at the taskfile level, only inside the task:

version: 3

env:
  ENV: '{{default "dev" .ENV}}'
  STACK_NAME: '{{default "development" .STACK_NAME}}'

vars:
  COMPONENT_NAME:
    sh: if [[ {{.ENV}} == "prod" ]]; then echo com.company.ProductionComponent; else echo {{.ENV}}.{{.STACK_NAME}}.DevelopmentComponent; fi

tasks:
  debug:
    cmds:
      - echo {{.ENV}}
      - echo {{.STACK_NAME}}
      - echo {{.COMPONENT_NAME}}

Will produce:

$ task debug ENV=prod STACK_NAME=production
task: [debug] echo prod
prod
task: [debug] echo production
production
task: [debug] echo dev.development.DevelopmentComponent
dev.development.DevelopmentComponent

Moving the COMPONENT_NAME variable declaration to task level OR moving it to env section and referencing it as an environment variable ($COMPONENT_NAME) fixes the issue. But this also looks like a related bug to me. If not, I can open a separate issue about it.

@pd93 pd93 removed the type: bug Something not working as intended. label Dec 16, 2024
@TheAceMan
Copy link

This looks like a similar issue to #1742 which has a PR for a potential fix.

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

No branches or pull requests

5 participants