メインコンテンツまでスキップ

Configuring the Build Cache for React Native in non-Bitrise CI environments

The Bitrise Build Cache CLI can be downloaded and run on any third-party CI provider (GitHub Actions, GitLab CI, CircleCI, Jenkins, etc.).

You can also set this up with an AI coding agent instead of following the steps manually. See Getting started with AI.

Using GitHub Actions

There is a dedicated guide with GitHub Actions workflow examples: Configuring the Build Cache for React Native in GitHub Actions.

On Bitrise Build Hub runners you don't need a token at all: the machine is already connected to your Bitrise Workspace, so the CLI authenticates itself. The steps below cover every other environment.

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​

  1. Create a workspace API token with at least the viewer workspace role.

  2. Get your Workspace slug.

  3. Set two variables in your CI provider's secret/environment settings:

    • BITRISE_BUILD_CACHE_AUTH_TOKEN: the workspace API token.
    • BITRISE_BUILD_CACHE_WORKSPACE_ID: your workspace slug.
  4. Add the following script to your CI pipeline before any Step that runs a build.

    It must run in the same environment (same shell, same container) as the build commands it's meant to accelerate.

    #!/usr/bin/env bash
    set -euxo pipefail

    # Download the Bitrise Build Cache CLI.
    curl --retry 5 -sSfL \
    'https://raw.githubusercontent.com/bitrise-io/bitrise-build-cache-cli/main/install/installer.sh' \
    | sh -s -- -b /tmp/bin -d

    # Activate Build Cache for React Native (Gradle + Xcode + ccache for C++).
    /tmp/bin/bitrise-build-cache activate react-native

    By default this enables all three backends. To disable a backend, pass the matching flag:

    /tmp/bin/bitrise-build-cache activate react-native --gradle=true --xcode=true --cpp=false

    CI is normally the environment that fills the cache. Pass --cache-push to activate write access alongside reads:

    /tmp/bin/bitrise-build-cache activate react-native --cache-push
    注記

    If you have previously used the Bitrise Build Cache CLI for Gradle or Xcode only, make sure you are on CLI v1.0.0 or later to get React Native support.

  5. After activation, the bitrise-build-cache binary is on PATH. Prefix any command that runs a build with bitrise-build-cache react-native run.

    注記

    For more information about wrapping, see Wrapping native build commands.

Example configuration: GitHub Actions

For GitHub Actions workflow examples, including jobs running on Bitrise Build Hub runners, see Configuring the Build Cache for React Native in GitHub Actions.

Validating the setupClick to copy link​

  1. Run a build with the new configuration. The activation step should complete successfully.
  2. Open the Build details page on Bitrise and check the Build Cache tab. You should see the wrapped commands listed with their cache stats.
  3. The first build will report 0% cache hit rate: the cache is empty at this point. This is expected.
  4. Run 1–3 additional builds to warm the cache. Subsequent builds should report a hit rate above 0%.
  5. You can monitor cache performance per build and across builds on the Build Cache list page.