Configuring the Build Cache for Bazel in non-Bitrise CI environments
The Bitrise Build Cache does not require using the Bitrise CI. You can use other CI/CD services and still take advantage of remote caching to improve your Bazel build times.
To do so, you need to configure your CI environment to download the Bitrise Build Cache CLI during the build and then run the CLI to enable the Bitrise Build Cache.
You can also set this up with an AI coding agent instead of following the steps manually. See Getting started with AI.
There is a dedicated guide with GitHub Actions workflow examples: Configuring the Build Cache for Bazel in GitHub Actions.
Selecting a tokenClick to copy link
For a CI integration, use a workspace API token. It belongs to the workspace instead of to a person, so your builds keep working when someone changes roles or leaves the company.
A Personal Access Token also works, but it carries the roles of the user who created it and stops working when that user leaves the workspace.
On your own machine you need neither: the CLI signs you in through the browser and stores the credentials in the OS keychain. See Setting up in a local dev environment for the local guide of your build tool.
Configuring the cacheClick to copy link
-
Create a workspace API token and copy its value.
Give the token at least the viewer workspace role: that is the lowest role that can access the Build Cache.
-
Get your workspace slug: open the Workspace settings page and select General settings on the left navigation menu.
-
Set the following Environment Variables in your CI configuration:
BITRISE_BUILD_CACHE_AUTH_TOKEN: the workspace API token.BITRISE_BUILD_CACHE_WORKSPACE_ID: the Bitrise workspace slug.
-
Add the following script to your CI configuration before the step you want to speed up:
EnvironmentMake sure to run the script in the same environment as the Bazel command you want to speed up. For example, if you use multiple Docker containers throughout the build, make sure that the Bitrise Build Cache CLI runs in the same Docker container as the Bazel command.
#!/usr/bin/env bashset -euxo pipefail# download Bitrise Build Cache CLI into the user-local bin dir so bazel can# resolve it by name via `--credential_helper`mkdir -p "$HOME/.local/bin"curl --retry 5 -sSfL 'https://raw.githubusercontent.com/bitrise-io/bitrise-build-cache-cli/main/install/installer.sh' | sh -s -- -b "$HOME/.local/bin" -dexport PATH="$HOME/.local/bin:$PATH"# run the CLI to enable Bitrise build cache for Bazelbitrise-build-cache activate bazel --cache --cache-push -
If you have Remote Build Execution enabled for your workspace, you can also use it locally by adding the
--rbeflag.Enabling RBE locallyYou will need to have the workers set up for your workspace, and the pool configuration in your repository’s
.bazelrcfile before enabling RBE locally!