Skip to main content

Bitrise Build Cache for Bazel

Abstract

To successfully use remote caching for Bazel, you need a bitrise.bazelrc file that contains the necessary configurations to enable the remote build cache for your Bazel project. You can use the remote cache for builds running on Bitrise or in other CI environments.

Try it for free

We offer a 30-day free trial at no cost; you don't even need to provide payment information. The trial starts automatically when you set up the Bitrise Build Cache.

Click here to get started with the Bitrise Build Cache. If you don't have a Bitrise account, you will be prompted to create one first before proceeding to set up the Build Cache.

To successfully use the Bitrise Build Cache for Bazel, you need a bitrise.bazelrc file that contains the necessary configurations to enable the cache for your Bazel project. You can use the Bitrise Build Cache for builds running on Bitrise or in other CI environments.

Configuring the Bitrise Build Cache for Bazel in the Bitrise CI environment

You can use the Bitrise Build Cache for Bazel on the Bitrise CI by adding our dedicated Step to your Workflow. The Step activates the Bitrise Build Cache. After it executes, Bazel builds will automatically read from the build cache and push new entries if it's enabled.

Workflow Editor

bitrise.yml

  1. Log in to Bitrise and select Bitrise CI on the left, then select your project.

  2. Click the Workflows button on the main page.

  3. Add the Activate Bitrise Build Cache for Bazel Step to your Workflow.

    The Step requires no configuration.

  • Open the bitrise.yml file and add the activate-build-cache-for-bazel Step to your Workflow.

    The Step requires no configuration.

    your-workflow:
      steps:
        - git-clone: {}
        - activate-build-cache-for-bazel:
    

During your first build, outputs will be saved to cache. We recommend running a couple of builds to ensure the cache is warmed up.

Configuring the Bitrise 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.

  1. 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.

  2. 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.

  3. 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.

  4. 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 enable-for bazel