`env` attribute of `*_binary` rules not applied when used via `--run_under`
- Dominant language
- Java
- Stars
- 25.8k
- Forks
- 4.6k
- Avg merge
- 2d 20h
- Merged PRs (30d)
- 72
Description
### Description of the bug:
Example:
```
sh_binary(
name = "my_script",
srcs = ["my_script.sh"],
env = {"FOO": "BAR"},
)
```
If I do `bazel test --run_under=//:my_script //:my_test`, then the `env` attribute of `my_script` is not used.
I would somehow expect that it does, because the script is being `run`.
This is particularly needed when the script needs to access the location of some `data` to function correctly:
```
sh_binary(
name = "my_script",
srcs = ["my_script.sh"],
data = ["@some//:data"],
env = {"DATA_LOCATION": "$(rlocationpath @some//:data)"},
)
```
### Which category does this issue belong to?
Core
### What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
_No response_
### Which operating system are you running Bazel on?
Ubuntu 24.04
### What is the output of `bazel info release`?
8.6.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 HEAD` ?
```text
```
### If this is a regression, please try to identify the Bazel commit where the bug was introduced with bazelisk --bisect.
_No response_
### Have you found anything relevant by searching the web?
_No response_
### Any other information, logs, or outputs that you want to share?
_No response_
Contributor guide
Research direction
Reproduce the issue with the shown sh_binary and bazel test --run_under command, then compare the environment seen by the wrapper with the environment from a direct run. Trace how --run_under launches the binary and how its env and data attributes are propagated; done means FOO and DATA_LOCATION are available when the wrapper runs.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- shell
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100