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

Unable to override dotenv file loaded using $ENV value, as per the example in the docs #1596

Closed
toby-griffiths opened this issue Apr 16, 2024 · 2 comments

Comments

@toby-griffiths
Copy link

  • Task version: Task version: v3.36.0 (h1:XVJ5hQ5hdzTAulHpAGzbUMUuYr9MUOEQFOFazI3hUsY=)
  • Operating system: MacOS 14.1.2
  • Experiments enabled…
* GENTLE_FORCE:         off
* REMOTE_TASKFILES: off
* ANY_VARIABLES:    off

Following the example in this docs here I've created the following files

# Taskfile
version: '3'

env:
    ENV: testing

dotenv: ['.env', '{{.ENV}}/.env']

tasks:
    greet:
        cmds:
            - echo "Using $KEYNAME and endpoint $ENDPOINT"
# .env
KEYNAME=VALUE
# testing/.env
ENDPOINT=testing.com
# wibble/.env
ENDPOINT=wibble.com

If I run task greet, I get…

$ task greet
task: [greet] echo "Using $KEYNAME and endpoint $ENDPOINT"
Using VALUE and endpoint testing.com

If I run ENV=wibble task greet, I get…

$ ENV=wibble task greet
task: [greet] echo "Using $KEYNAME and endpoint $ENDPOINT"
Using VALUE and endpoint testing.com

$ export ENV=wibble
$ task greet
task: [greet] echo "Using $KEYNAME and endpoint $ENDPOINT"
Using VALUE and endpoint testing.com

I would expect that if I set ENV=wibble I should see env vars from the wibble/.env file, but I cannot get this working.

No matter what I try, I cannot get this working other than changing the env value in the Taskfile itself to get the alternative env var values.

Am I missing something obvious, or is this a bug?

@task-bot task-bot added the state: needs triage Waiting to be triaged by a maintainer. label Apr 16, 2024
@marziply
Copy link

I am experiencing the same bug.

@vmaerten
Copy link
Collaborator

Hello @toby-griffiths

To do what you are trying to do, you need to use the default fonction in the go templating. This is working :

# Taskfile
version: '3'

env:
  ENV: '{{.ENV | default "testing"}}'

dotenv: ['.env', '{{.ENV}}/.env']

tasks:
  greet:
    cmds:
      - echo "Using $KEYNAME and endpoint $ENDPOINT"
➜ task greet                                                                                                                                                                                                                                                                               
task: [greet] echo "Using $KEYNAME and endpoint $ENDPOINT"
Using VALUE and endpoint testing.com

➜ ENV=wibble task  greet                                                                                                                                                                                                                                                                   
task: [greet] echo "Using $KEYNAME and endpoint $ENDPOINT"
Using VALUE and endpoint wibble.com

@vmaerten vmaerten removed the state: needs triage Waiting to be triaged by a maintainer. label May 16, 2024
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

4 participants