task icon indicating copy to clipboard operation
task copied to clipboard

Environment variable are loaded by dotenv before dependency tasks are executed

Open gsantoro opened this issue 2 years ago • 3 comments

Hello devs and thanks again for this great tool.

Today I have experienced a weird issue that I would like to verify with someone else here.

I would like to execute a task called test-pipeline that has a dependency task env-variables that creates an .env file at the location pointed by the variable .ENV_FILE.

  test-pipeline:
    deps:
      - env-variables  # create .ENV_FILE
    dotenv: 
      - "{{.ENV_FILE}}"
    cmds: 
      - <my BASH code thats needs env variables from {{.ENV_FILE}}>

I am expecting that if the .env file doesn't exists yet, it will be created by the task env-variables and then used by the task test-pipeline.

In reality this works as expected only if the .env file already exists. In order to make it works I need to run the following code instead.

  test-pipeline:
    deps:
      - env-variables # create .ENV_FILE
    cmds: 
      - |
        dotenv -f {{.ENV_FILE}} run -- bash -c \
          '<my BASH code thats needs env variables from {{.ENV_FILE}}>'

As you can see I need to use the binary dotenv from python-dotenv instead of the dotenv from Taskfile

Am I doing something wrong?

  • TTask version: v3.20.0
  • Operating System: Mac Os with M1 chip

gsantoro avatar Feb 10 '23 19:02 gsantoro