Search code examples
bazel

Why is BUILD_WORKSPACE_DIRECTORY not getting set?


I'm using bazel 5.1.0 and have the following in a BUILD file:

sh_binary(
    name = "aoeu",
    srcs = ["aoeu.sh"]
)

The contents of aoeu.sh is:

#!/bin/bash

echo "BAZEL_WORKSPACE_DIRECTORY=${BAZEL_WORKSPACE_DIRECTORY}"

When I bazel run aoeu, the output is BAZEL_WORKSPACE_DIRECTORY=.

Based on https://docs.bazel.build/versions/main/user-manual.html, my understanding is that BAZEL_WORKSPACE_DIRECTORY should be set. Why isn't it?


Solution

  • The desired environmental variable is called BUILD_WORKSPACE_DIRECTORY not BAZEL_WORKSPACE_DIRECTORY.