Bazel: Allow bazelrc to use Environment Variables.

Created on 14 Feb 2018  Â·  4Comments  Â·  Source: bazelbuild/bazel

ATTENTION! Please read and follow:

Description of the problem / feature request:

Right now, I could not find a way to use environment variables in .bazelrc.
What i want to do is

$export GIT_ROOT=/workspace/project_name
and then in /workspace/project_name/.bazelrc
$cat /workspace/project_name/.bazelrc
build --action_env=GIT_ROOT="$GIT_ROOT"  # where $GIT_ROOT is the environment variable.

Feature requests: what underlying problem are you trying to solve with this feature?

Pass on Environment variable to a bazel rule which runs a script.

Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

What operating system are you running Bazel on?

Linux and mac

What's the output of bazel info release?

latest

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

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

Have you found anything relevant by searching the web?

Read,

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

Most helpful comment

@ittaiz Yes, the case of "I want to have an environment variable available in the environment of my running actions" should be solved via --action_env=MY_VAR.

The case of "I want to use environment variables in my .bazelrc via string interpolation" like build --jobs=$BAZEL_MAX_JOBS is not solved, but it's not clear if we should even support it.

If you want / need that, I'd suggest to file a new FR for that :)

All 4 comments

Right now, I could not find a way to use environment variables in .bazelrc.
What i want to do is
$export GIT_ROOT=/workspace/project_name
and then in /workspace/project_name/.bazelrc
$cat /workspace/project_name/.bazelrc
build --action_env=GIT_ROOT="$GIT_ROOT" where $GIT_ROOT is the environment variable.

specifying --action_env with just the variable names tells bazel to inherit
that variable from the caller environment. So, adding

build --action_evn=GIT_ROOT

to the respective rc-file and an exporting GIT_ROOT in your shell provides
the information to actions without the need of changing the syntax of rc-files.

--
Klaus Aehlig
Google Germany GmbH, Erika-Mann-Str. 33, 80636 Muenchen
Registergericht und -nummer: Hamburg, HRB 86891
Sitz der Gesellschaft: Hamburg
Geschaeftsfuehrer: Paul Terence Manicle, Halimah DeLaine Prado

Seems like this is solved, closing. Please reopen if necessary.

Just to make sure- the general feature isn’t solved but the specific case,
right?
On Thu, 15 Feb 2018 at 17:56 Philipp Wollermann notifications@github.com
wrote:

Closed #4635 https://github.com/bazelbuild/bazel/issues/4635.

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/bazelbuild/bazel/issues/4635#event-1476172060, or mute
the thread
https://github.com/notifications/unsubscribe-auth/ABUIF0Q7-biDeWbgQDmjPPYOBCkbNmAPks5tVFOjgaJpZM4SEvZd
.

@ittaiz Yes, the case of "I want to have an environment variable available in the environment of my running actions" should be solved via --action_env=MY_VAR.

The case of "I want to use environment variables in my .bazelrc via string interpolation" like build --jobs=$BAZEL_MAX_JOBS is not solved, but it's not clear if we should even support it.

If you want / need that, I'd suggest to file a new FR for that :)

Was this page helpful?
0 / 5 - 0 ratings