Use Remote Caching from External CI/CD
You can use Vercel Remote Cache with Turborepo from an external CI/CD provider, so your pipelines share the same cache as your team. There are two ways to authenticate:
- OpenID Connect (OIDC): configure a policy that allows exchanging the CI/CD provider's OIDC tokens for short-lived Turborepo access tokens that grant access to Remote Cache (recommended).
- Personal Access Token (PAT): configure a long-lived, team-scoped PAT as a secret in your CI/CD provider (use when OIDC is not an option).
To set up Remote Caching on your own machine instead, see Remote Caching.
When you use OIDC to authenticate, you exchange your CI/CD provider's OIDC token for a short-lived Turborepo access token and set it in the TURBO_TOKEN environment variable.
Unlike a Personal Access Token (PAT), the Turborepo access token
- is short-lived
- only grants access to Vercel Remote Cache
- is associated to your team, rather than a specific team member
Follow the steps below to set it up.
On the Vercel dashboard, go to your team's Settings → Build and Deployment → OIDC Policies for CLI Access, then click Add next to Turborepo CLI Policies.
Clicking Add opens a form to add a Turborepo CLI policy. Fill out the form with a policy name. If your CI/CD provider is listed, select it; otherwise, you can configure specific OIDC issuer and claims to match on.
For example, if you are using GitHub, select your GitHub account and repository that hosts the CI/CD workflows you want to grant access to. You can optionally restrict the policy to a specific workflow or branch, and customize the audience.
Create a repository variable named
TURBO_TEAMset to your team slug, which is the part aftervercel.com/in your team URL. For example, the slug forvercel.com/acmeisacme.The exact steps depend on your CI/CD provider. For GitHub, use the GitHub CLI from your repository:
Terminalgh variable set TURBO_TEAM --body "your-team-slug"Or add it through the GitHub UI under Settings → Secrets and variables → Actions, on the Variables tab.
Add
vercel/setup-turborepo-remote-cache-actionbefore any step that runsturbo. The action needs theid-token: writepermission so it can request a GitHub OIDC token, exchange it for a short-lived Turborepo access token, and setTURBO_TOKENandTURBO_TEAMfor later steps..github/workflows/ci.yml# ... jobs: build: name: Build and Test timeout-minutes: 15 runs-on: ubuntu-latest permissions: contents: read id-token: write steps: - name: Check out code uses: actions/checkout@v4 with: fetch-depth: 2 - name: Set up Turborepo Remote Cache uses: vercel/setup-turborepo-remote-cache-action@v1.0.0 with: team: ${{ vars.TURBO_TEAM }} # ...For any other provider, request an OIDC token from it with the audience your policy expects, then exchange that token for a short-lived Turborepo access token. Set the result as
TURBO_TOKENand your team slug asTURBO_TEAMbefore runningturbo:exchange-oidc-token.sh# $OIDC_TOKEN: the OIDC token issued by your CI/CD provider # $TURBO_TEAM: your Vercel team ID or slug export TURBO_TOKEN=$(curl -sS -f -X POST https://api.vercel.com/login/oauth/token \ --data "grant_type=urn:ietf:params:oauth:grant-type:token-exchange" \ --data "client_id=cl_kyUx2zVvA4MGptBohkmtYHJly2XltXzD" \ --data "subject_token_type=urn:ietf:params:oauth:token-type:id_token" \ --data "requested_token_type=urn:ietf:params:oauth:token-type:access_token" \ --data-urlencode "team_id_or_slug=$TURBO_TEAM" \ --data-urlencode "subject_token=$OIDC_TOKEN" \ | jq -r '.access_token')
If your CI/CD provider doesn't support OIDC, you can authenticate with a Personal Access Token (PAT).
Scope the PAT to the Vercel team you want to share artifacts with, so that you don't grant it more access than necessary.
Then add the following environment variables to your workflow to make them available to your turbo commands:
TURBO_TOKEN: PAT scoped to the Vercel team to share artifacts withTURBO_TEAM: slug of the Vercel team to share artifacts with
Create a scoped access token in the Vercel dashboard, then copy the value somewhere safe. You'll need it in the next step.
Create a secret named
TURBO_TOKENset to the access token you just created. The exact steps depend on your CI/CD provider. For GitHub, use the GitHub CLI:Terminalgh secret set TURBO_TOKENPaste the token value when prompted. Or add it through the GitHub UI under Settings → Secrets and variables → Actions, on the Secrets tab.
Create a repository variable named
TURBO_TEAMset to your team slug, which is the part aftervercel.com/in your team URL. For example, the slug forvercel.com/acmeisacme.The exact steps depend on your CI/CD provider. For GitHub, use the GitHub CLI from your repository:
Terminalgh variable set TURBO_TEAM --body "your-team-slug"Or add it through the GitHub UI under Settings → Secrets and variables → Actions, on the Variables tab.
The exact steps will vary depending on your CI/CD provider. For example, if you are using GitHub, provide the environment variables to any job that runs
turbo..github/workflows/ci.yml# ... jobs: build: name: Build and Test timeout-minutes: 15 runs-on: ubuntu-latest env: TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }} TURBO_TEAM: ${{ vars.TURBO_TEAM }} steps: - name: Check out code uses: actions/checkout@v4 with: fetch-depth: 2 # ...
Was this helpful?