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

Add support for setting Environment Variables via Run Configuration #2042

Closed
KaoruDev opened this issue Aug 14, 2020 · 18 comments · Fixed by #5771
Closed

Add support for setting Environment Variables via Run Configuration #2042

KaoruDev opened this issue Aug 14, 2020 · 18 comments · Fixed by #5771
Labels
lang: java Java rules integration P3 We're not considering working on this, but happy to review a PR. (No assignee) product: IntelliJ IntelliJ plugin type: feature request

Comments

@KaoruDev
Copy link

This may be a naive request since I have no knowledge Intellij's Plugin API, but would it be possible to add a field in Bazel run configurations to be able to set ad-hoc environment variables for a given executable?

For example, the Java run configurations have this field available allowing for environment variables to be set per run configuration:

image

Intellij docs capture the ability:
https://www.jetbrains.com/help/idea/run-debug-configuration-application.html


At the moment my current workaround is to add an export VAR=value to my shell dotfile, which is error-prone and difficult to manage 😭

@HunterEl
Copy link

HunterEl commented Jan 5, 2021

Also running into this and would love to see support for this through Intellij.

@ns476
Copy link

ns476 commented Apr 22, 2021

As a slightly grim workaround, you can use --run_under like so:

Screenshot from 2021-04-22 14-16-13

@graysonchao
Copy link

@ns476 That's still way better than launching intellij from the CLI with env vars set, which is what I was doing. Thanks!

@rodrigodiez
Copy link

@ns476 your approach works for me but unfortunately can't debug with it

could not launch process: not an executable file

@JamyDev
Copy link
Contributor

JamyDev commented May 17, 2022

@alice-ks I have an idea to implement this by re-using the EnvironmentVariablesState component that is used by the Python run config, but making it global by applying it in ScopedBlazeProcessHandler using .withEnvironment. But ScopedBlazeProcessHandler show the component and apply this when it's a BlazeCommandName.RUN config. (since test wraps the process, so it needs to be defined using --test_env).

Does this sound like a reasonable approach? I can submit a PR if it is.

Especially since --run_under doesn't work in various scenarios (eg debug)

@trinque
Copy link

trinque commented Nov 19, 2022

@JamyDev just curious whether this progressed. Environment variables are a common way to supply runtime parameters to services running in k8s, so this would be very useful!

@JamyDev
Copy link
Contributor

JamyDev commented Nov 22, 2022

@trinque We have this in our internal fork, so I guess I could PR it. But I never got an answer from the maintainers so kind of lost track of it :))

@trinque
Copy link

trinque commented Nov 25, 2022

If it's not too much trouble, I'd greatly appreciate it!

Plugin maintainers, can we get @JamyDev some love on this potential PR? Not being able to set environment variables is making for brittle work-arounds on our end.

@JamyDev if you need help getting that PR over the finish line, I'm happy to help however I can, including contributing code.

@JamyDev
Copy link
Contributor

JamyDev commented Nov 28, 2022

@trinque created the PR, need someone to test it on a Java run target though, since I don't have any (besides the plugin itself)

@sgowroji sgowroji added lang: java Java rules integration awaiting-maintainer Awaiting review from Bazel team on issues labels Nov 29, 2022
@trinque
Copy link

trinque commented Dec 1, 2022

Very cool! I built and tested locally and saw the new environment variable field was present for a py_binary rule, but the field is not showing up for a java_binary rule yet.

I'll dig in and see if I can understand why.

@JamyDev
Copy link
Contributor

JamyDev commented Dec 1, 2022

@trinque I can see it show up for my test:
image

Not sure why it says "Generic Handler" though

@mai93 mai93 removed the awaiting-maintainer Awaiting review from Bazel team on issues label Jan 16, 2023
@mai93 mai93 added the P3 We're not considering working on this, but happy to review a PR. (No assignee) label Apr 4, 2023
@mai93 mai93 removed their assignment Apr 4, 2023
@github-actions
Copy link

github-actions bot commented Oct 5, 2023

Thank you for contributing to the IntelliJ repository! This issue has been marked as stale since it has not had any activity in the last 6 months. It will be closed in the next 14 days unless any other activity occurs or one of the following labels is added: "not stale", "awaiting-maintainer". Please reach out to the triage team (@bazelbuild/triage) if you think this issue is still relevant or you are interested in getting the issue resolved.

@github-actions github-actions bot added the stale Issues or PRs that are stale (no activity for 30 days) label Oct 5, 2023
@jorunfa
Copy link

jorunfa commented Oct 6, 2023

I see this is marked as stale. Would still like this feature 🙏

But the run under trick did actually work, so that's great 🎉. I've been searching for that answer for years.

@github-actions github-actions bot removed the stale Issues or PRs that are stale (no activity for 30 days) label Oct 7, 2023
@andystroz
Copy link

Also interested in this being baked into the IntelliJ UI like most other Run/Debug configurations.

@edwardotis
Copy link

+1, repeatedly adding the same environment variables to each config really makes it to tedious to use bazel with intellij.

@ahmedyarub
Copy link
Contributor

Looking forward to this one :)

@dieortin
Copy link

@ahmedyarub it's already available in the latest version

@ahmedyarub
Copy link
Contributor

@ahmedyarub it's already available in the latest version

What about #5885?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lang: java Java rules integration P3 We're not considering working on this, but happy to review a PR. (No assignee) product: IntelliJ IntelliJ plugin type: feature request
Projects
Development

Successfully merging a pull request may close this issue.