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.
-
Generate a Personal Access Token on Bitrise: Creating a personal access token.
Copy the value of the token, as you will need it during the process.
-
Find your Workspace ID: open the Workspace settings page and select General settings on the left navigation menu. You can find and copy the slug from there.
-
Set the following Environment Variables in your CI configuration:
-
BITRISE_BUILD_CACHE_AUTH_TOKEN
: The value should be your Personal Access Token. -
BITRISE_BUILD_CACHE_WORKSPACE_ID
: The value should be the Bitrise Workspace slug.
-
-
Add the following script to your CI configuration before the step you want to speed up:
Environment
Make 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 bash set -euxo pipefail # download Bitrise Build Cache CLI curl -sSfL 'https://raw.githubusercontent.com/bitrise-io/bitrise-build-cache-cli/main/install/installer.sh' | sh -s -- -b /tmp/bin -d # run the CLI to enable Bitrise build cache for Bazel /tmp/bin/bitrise-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
--rbe
flag.Enabling RBE locally
You will need to have the workers set up for your workspace, and the pool configuration in your repository’s
.bazelrc
file before enabling RBE locally!