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

convert env var defined in .env as variable #379

Closed
kernel164 opened this issue Sep 18, 2020 · 5 comments
Closed

convert env var defined in .env as variable #379

kernel164 opened this issue Sep 18, 2020 · 5 comments
Labels
area: variables Changes related to variables.

Comments

@kernel164
Copy link

os: macos
Task version: 3.0.0

.env

XYZ=1

Taskfile.yml

version: "3"
dotenv: [".env"]
vars:
  XYZ: 
    sh: echo "$XYZ"
tasks:
  test:
    cmds: 
      - echo "{{ .XYZ }}" # is empty always
      - echo "$XYZ" # echo 1
      #- echo "{{ split "." $XYZ }}" # fails can't use env var inside go template

Output:

task test
task: echo ""

task: echo "$XYZ"
1
@andreynering andreynering added the type: bug Something not working as intended. label Oct 3, 2020
@andreynering
Copy link
Member

Hi @kernel164,

Thanks for reporting, this is indeed a bug

@duboiss
Copy link

duboiss commented Nov 17, 2020

I don't really know if this has a relation but:

APP_ENV=dev
dotenv: ['.env']

env:
    ...

vars:
    ENV: $APP_ENV

tasks:
    hmm:
        cmds:
            - echo $APP_ENV

"APP_ENV": executable file not found in $PATH

Same if I replace echo $APP_ENV by echo "{{.ENV}}" or echo {{.ENV}}.

I need to initialize a global variable with an .env value (default bahavior).
Because this Tasfkile.yml will be shared by several people, some will want to assign a fixed value like "dev" or "prod" instead of basing it on the .env APP_ENV.

@Jakob-Koschel
Copy link

I believe I have the same issue as well. Looks like environment variables are not usable within vars.
Also variables defined in .env files cannot be used within

env:
    INCREMENTAL: $APP_ENV/build

where .env contains: APP_ENV=/home/path

This is quite crucial if you only want to have environment specific variables in .env and all variables derived from that in the script.

Otherwise you'll have to do this in the .env file:

APP_ENV=/home/path
INCREMENTAL=$APP_ENV/build

@andreynering andreynering added the area: variables Changes related to variables. label Jan 12, 2021
@andreynering
Copy link
Member

Fixed in master

@Jakob-Koschel
Copy link

Thanks a lot for working on this! I've just tested this and looks like it is broken in the way I'm trying to use this.

this works:

.env:

TEST=/home/test/.local/bin

Taskfile.yml:

version: '3'

dotenv: ['.env']

env:
  TEST1: X$TEST/.local/bin

tasks:
  test:
    cmds:
      - echo $TEST1

However when removing the X from the TEST1: line, it breaks.

I get the following error message:

stat /home/<...>/Developer/test/TEST/.local/bin: no such file or directory
task: Command "TEST/.local/bin" in taskvars file failed: exit status 127

I did not dig deep in the code to understand why this is happening, maybe you got an idea.

Thanks in advance!

@pd93 pd93 removed the type: bug Something not working as intended. label Dec 16, 2024
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