# 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](/bitrise-build-cache/getting-started-with-the-build-cache/getting-started-with-ai).

:::tip[Using GitHub Actions]

There is a dedicated guide with GitHub Actions workflow examples: [Configuring the Build Cache for React Native in GitHub Actions](/bitrise-build-cache/build-cache-for-react-native/configuring-the-build-cache-for-react-native-in-github-actions).

On [Bitrise Build Hub](/bitrise-build-hub/build-hub-for-github-actions/build-hub-for-github-actions-overview) 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 token

For a CI integration, use a [workspace API token](/bitrise-platform/workspaces/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](/bitrise-platform/accounts/personal-access-tokens) 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](/bitrise-build-cache/getting-started-with-the-build-cache/getting-started-with-the-build-cache#setting-up-in-a-local-dev-environment) for the local guide of your build tool.

## Configuring the cache

1. Create a [workspace API token](/bitrise-platform/workspaces/workspace-api-token) with at least the **viewer** workspace role.
1. [Get your Workspace slug](/bitrise-ci/api/identifying-workspaces-and-apps-with-their-slugs).
1. 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.
1. 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.

   ```bash
   #!/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
   ```

   :::note

   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.

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

   :::note

   For more information about wrapping, see [Wrapping native build commands](/bitrise-build-cache/build-cache-for-react-native/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](/bitrise-build-cache/build-cache-for-react-native/configuring-the-build-cache-for-react-native-in-github-actions).

## Validating the setup

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