Buildkite

The following example shows how to use Turborepo with Buildkite.

For a given root package.json:

./package.json
{
  "name": "my-turborepo",
  "scripts": {
    "build": "turbo run build",
    "test": "turbo run test"
  },
  "devDependencies": {
    "turbo": "latest"
  }
}

And a turbo.json:

Turborepo logo
./turbo.json
{
  "$schema": "https://turborepo.com/schema.json",
  "tasks": {
    "build": {
      "outputs": [".next/**", "!.next/cache/**"],
      "dependsOn": ["^build"]
    },
    "test": {
      "dependsOn": ["^build"]
    }
  }
}

Create a file called .buildkite/pipeline.yml in your repository with the following contents:

.buildkite/pipeline.yml
steps:
  - label: ":test_tube: Test"
    command: |
      pnpm install
      pnpm test
 
  - label: ":hammer: Build"
    command: |
      pnpm install
      pnpm build

Create a Pipeline

To create your pipeline in the Buildkite dashboard, you'll need to first upload the pipeline definition from your repository.

  1. Select Pipelines to navigate to the Buildkite dashboard.

  2. Select New pipeline.

  3. Enter your pipeline's details in the respective Name and Description fields.

  4. In the Steps editor, ensure there's a step to upload the definition from your repository:

.buildkite/pipeline.yml
steps:
  - label: ':pipeline:'
    command: buildkite-agent pipeline upload
  1. Select Create Pipeline, then click New Build, then select Create Build.

Run the pipeline whenever you make changes you want to verify.

Remote Caching

To use Remote Caching, retrieve the team and token for the Remote Cache for your provider. In this example, we'll use Vercel Remote Cache:

  • TURBO_TOKEN - The Bearer token to access the Remote Cache
  • TURBO_TEAM - The account to which the monorepo belongs

To use Vercel Remote Caching, you can get the value of these variables in a few steps:

  1. Create a Scoped Access Token to your account in the Vercel Dashboard. Copy the value to a safe place. You'll need it in a moment.

    Vercel Access Tokens

  2. Obtain your Team URL and copy its value as well. Both values will be used in the next step.

  3. In the Buildkite dashboard, create two new Buildkite secrets, one for each value. Name them TURBO_TOKEN and TURBO_TEAM.

  4. Update pipeline.yml to fetch and apply TURBO_TOKEN and TURBO_TEAM as environment variables with the Buildkite Secrets plugin as shown. (For additional secret-management options, read Managing pipeline secrets in the Buildkite documentation.)

    .buildkite/pipeline.yml
    steps:
      - label: ':test_tube: Test'
        command: |
          npm install
          npm test
        plugins:
          - secrets:
              variables:
                TURBO_TOKEN: TURBO_TOKEN
                TURBO_TEAM: TURBO_TEAM
     
      - label: ':hammer: Build'
        command: |
          npm install
          npm run build
        plugins:
          - secrets:
              variables:
                TURBO_TOKEN: TURBO_TOKEN
                TURBO_TEAM: TURBO_TEAM

    Commit and push these changes to your repository, and on the next pipeline run, the secrets will be applied and Vercel Remote Caching will be active.