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

Feature: Dynamically added env variables #1786

Open
michaszcz opened this issue Sep 4, 2024 · 2 comments
Open

Feature: Dynamically added env variables #1786

michaszcz opened this issue Sep 4, 2024 · 2 comments

Comments

@michaszcz
Copy link

I'd like to have some option to set env variables dynamically for all steps of the task.

Example 1:

version: '3'

tasks:
  greet:
    cmds:
      - export GREETING=Hello
      - echo $GREETING  # Currently it'll print an empty string, I'd like to receive the value `Hello`

Example 2:

version: '3'

tasks:
  task_name:
    dynamic_env:  # Currently not possible
      sh: python script_that_exports_env_variables.py
    cmds:
      - echo $DYNAMIC_VAR1 $DYNAMIC_VAR2  # Env vars set by the script

Without the feature I have to export variables and use them in one step - example:
Example 2:

version: '3'

tasks:
  task_name:
    cmds:
      - ./export_vars.sh && echo $DYNAMIC_VAR1 $DYNAMIC_VAR2
      - echo $DYNAMIC_VAR1 $DYNAMIC_VAR2  # Currently vars are not available in this step
@task-bot task-bot added the state: needs triage Waiting to be triaged by a maintainer. label Sep 4, 2024
@vmaerten
Copy link
Member

This is possible to set dynamic env variable but only one at the same time :

version: '3'

tasks:
  greet:
    env:
      GREETING: {sh: echo 'hello'}
      FOO: bar
    cmds:
      - echo $GREETING

If you want to add multiple env variable at the same time, I would use dotenv files and follow this issue : #1381

@vmaerten vmaerten added state: awaiting response Waiting for issue author to respond. and removed state: needs triage Waiting to be triaged by a maintainer. labels Sep 21, 2024
@michaszcz
Copy link
Author

Even if dotenv were available, it would still have a few issues:

  1. It would require generating a dotenv file and removing it after task execution, which could cause issues in parallel execution.
  2. Environment variables must remain the same throughout the task's execution.

@task-bot task-bot removed the state: awaiting response Waiting for issue author to respond. label Sep 24, 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

3 participants