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

Allow calling shell to pass environment variables to Actions environment #18586

Closed
mtribiere opened this issue Jun 6, 2023 · 9 comments
Closed
Labels
team-Local-Exec Issues and PRs for the Execution (Local) team type: feature request untriaged

Comments

@mtribiere
Copy link

mtribiere commented Jun 6, 2023

Description of the feature request:

Currently, Actions environment are a little odd, as there is no options to forward all environment variables to the Action environment. Just LD_LIBRARY_PATH and PATH are forwarded but there should be an options to forward them all.

This would be very useful in the embedded world, and old test benches who's configurations can't be changed.

What underlying problem are you trying to solve with this feature?

Allow old compilers and tools to benefits from Bazel. But those are picky and require their environment variables.

Which operating system are you running Bazel on?

Windows

What is the output of bazel info release?

release 6.2.0

If bazel info release returns development version or (@non-git), tell us how you built Bazel.

No response

What's the output of git remote get-url origin; git rev-parse master; git rev-parse HEAD ?

No response

Have you found anything relevant by searching the web?

#8578
https://groups.google.com/g/bazel-discuss/c/AZek-OR1t7A

Any other information, logs, or outputs that you want to share?

No response

@sgowroji sgowroji added the team-Local-Exec Issues and PRs for the Execution (Local) team label Jun 6, 2023
@fmeum
Copy link
Collaborator

fmeum commented Jun 6, 2023

You can forward environment variables individually via --action_env=VAR_NAME. Rules may choose to ignore the value, but the built-in ones don't.

If all variables were made available to an action, caching would probably become impossible. Is that really what you want? Is it possible to enumerate the variables consumed by the tools you are using?

@mtribiere
Copy link
Author

@fmeum Thanks for your quick answer.

The way it works right now is the following :

  • We have a .bat file that generate a bunch of environment variables based on different conditions
  • Those variables are exported to windows with set MYVAR=VALUE
  • Bazel is called to start the compilation

The problem right now, is that all those environment variables are accessible in the windows shell, and I cannot forward them all one by one to Bazel with --action_env=VAR_NAME. The solution to me would be an option to allow the forwarding of all environment variables, but I'm open to any suggestion you may have.

Thanks

@fmeum
Copy link
Collaborator

fmeum commented Jun 6, 2023

Could you elaborate on why forwarding them one-by-one wouldn't work? If the .bat file e.g. could write out an .env file instead of just executing set FOO=bar, that should be easy to massage into --action_env arguments for Bazel.

@mtribiere
Copy link
Author

I didn't made that very clear, my bad! Those variables are generated, including their names. There is no way to know which one will be produced in advanced, as this is based on a number of external factors.

@fmeum
Copy link
Collaborator

fmeum commented Jun 6, 2023

I see. So you have a script env.bat that when run modifies the environment in some way that is impossible to predict? If so, couldn't you run set before and after and have a separate script forward the values that have changed to Bazel? Even if Bazel had the ability to forward all environment variables to all actions, you would probably still want to trim it down in this way so that the cache remains useful.

@mtribiere
Copy link
Author

Exactly, the variables are generated at a custom configuration stage, before any compilation tool is called. Make sense, maybe an external tool would to the trick... Caching is indeed important for us.

@mtribiere
Copy link
Author

mtribiere commented Jun 6, 2023

I think I'm gonna go with that.
But just in case, how would you forward all variables, with the drawback of losing the cache ? Or maybe there isn't a feature like this just yet

@fmeum
Copy link
Collaborator

fmeum commented Jun 6, 2023

There is no way to do this as far as I know, mostly because features that would essentially prevent caching aren't really going to be considered.

Glad to hear that there is a path forward for you though.

@mtribiere
Copy link
Author

Thanks for your reactivity, that's very appreciated.

Closing the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
team-Local-Exec Issues and PRs for the Execution (Local) team type: feature request untriaged
Projects
None yet
Development

No branches or pull requests

4 participants