Skip to content

Exchange values between task and deps using dotenv files.#2711

Open
trulede wants to merge 1 commit intogo-task:mainfrom
trulede:PR/exchange-vars-with-dotenv-files
Open

Exchange values between task and deps using dotenv files.#2711
trulede wants to merge 1 commit intogo-task:mainfrom
trulede:PR/exchange-vars-with-dotenv-files

Conversation

@trulede
Copy link
Copy Markdown
Contributor

@trulede trulede commented Mar 1, 2026

This PR allows the exchange of variables between tasks, and depend tasks, using the dotenv mechanism.

If a task has deps and dotenv then the dotenv files are reloaded which makes them available in the environment of subsequent task commands.

Using this method the task does not need to be recompiled, which avoids complexities which might occur if templated variables in a task would change.

Fixes #1381 (and many others)
Fixes #1575
Fixes #2385
Fixes #1449

Alternative to #1746 (improves upon)
Related to #1627 (alternative to)

In general, works as you might expect:

version: '3'
tasks:
  gen:
    cmds:
      - echo "BAR=bar" > .genenv  
  default:
    dotenv:
      - .genenv
    deps:
      - gen
    cmds:
      - echo "BAR=$BAR"

@EvansJahja
Copy link
Copy Markdown

This would require writing to a file, feels like it's leaking context to the outside world, just because we don't have a ".RESULT" variable or something.

Also, concurrent tasks would be fighting on the same '.env' file

@trulede
Copy link
Copy Markdown
Contributor Author

trulede commented Apr 22, 2026

This would require writing to a file, feels like it's leaking context to the outside world, just because we don't have a ".RESULT" variable or something.

Also, concurrent tasks would be fighting on the same '.env' file

Its a normal way to do this. Simple to implement and easy to understand (and it already works!).
For more sophisticated use cases there things like Redis which can serve the same purpose without involving the filesystem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants