How can I make bazel use external storage when building?

Use the --output_user_root flag.

Example:

bazel --output_user_root=/path/to/directory build //foo:bar

I symlinked ~/.cache/bazel to a directory on my other drive. Looks to be working so far. i.e.

ln -s /mnt/otherdrive/bazel_cache ~/.cache/bazel

I thought to move the old cache to avoid rebuilding, but I noticed symlinks to directories within the cache and didn't want to deal with transferring those so they pointed to the new directory as well. So I just deleted the old cache, symlinked, and rebuilt.


You can change the outputRoot directory by changing the $TEST_TMPDIR variable.

export TEST_TMPDIR=/path/to/directory

From the bazel docs:

The outputRoot directory is ~/.cache/bazel. (Unless $TEST_TMPDIR is set, as in a test of bazel itself, in which case this directory is used instead.)

Tags:

Linux

Bazel