docs guides Quickstart: CI with Buildkite
07-buildkite-quickstart.md GuidesNov 22, 2026

Quickstart: CI with Buildkite

This page takes a GitStack repository with no CI to one where every land waits for a Buildkite build, step by step. It uses an example repository, acme/api, and a Buildkite pipeline also called api, on Buildkite's hosted agents. Swap in your own names as you go. CI with Buildkite has the same steps with every option, and the setup for agents you run yourself.

You need owner access to the repository and a Buildkite organization.

1. Add the pipeline file#

Buildkite reads the steps from a file in the repository. Give each step a key: GitStack reports each keyed step as its own check, named <pipeline>/<key>, so these two steps report api/lint and api/test. The env block lets the agent clone from GitStack, with the token step 5 stores:

yaml
# .buildkite/pipeline.yml
env:
  GIT_CONFIG_COUNT: "1"
  GIT_CONFIG_KEY_0: credential.https://gitstack.sh.helper
  GIT_CONFIG_VALUE_0: >-
    !f() { test "$$1" = get || exit 0; echo username=buildkite;
    printf 'password=%s\n' "$$(buildkite-agent secret get GITSTACK_FETCH_TOKEN)"; }; f

steps:
  - label: "Lint"
    key: lint
    command: make lint

  - label: "Test"
    key: test
    command: make test

Write $$ where you mean $, since Buildkite reads a single $ as a variable when it uploads the file. Land the file as a review. Nothing requires a check yet, so it lands at once:

bash
gs switch -c buildkite
gs add .buildkite/pipeline.yml
gs commit -m "ci: Buildkite pipeline" --review -t "ci: Buildkite pipeline"
gs submit

2. Create the pipeline in Buildkite#

In Buildkite, create a pipeline named api:

  • Repository: the GitStack clone URL, https://gitstack.sh/acme/api.git.

  • Steps: the same env block, and one step that runs buildkite-agent pipeline upload, which reads .buildkite/pipeline.yml from the commit being built. The agent clones before it reads anything from the repository, so the env block has to be here too:

    yaml
    env:
      GIT_CONFIG_COUNT: "1"
      GIT_CONFIG_KEY_0: credential.https://gitstack.sh.helper
      GIT_CONFIG_VALUE_0: >-
        !f() { test "$$1" = get || exit 0; echo username=buildkite;
        printf 'password=%s\n' "$$(buildkite-agent secret get GITSTACK_FETCH_TOKEN)"; }; f
    steps:
      - label: ":pipeline: upload"
        command: buildkite-agent pipeline upload
    

If acme/api is public, make the pipeline public too (its Settings, General), so contributors can read a build's log from the review.

3. Make an API token#

Under your Buildkite user's API Access Tokens, make a token for the pipeline's organization with the read_builds and write_builds scopes.

4. Connect the pipeline to GitStack#

In GitStack, open the repository's Settings, then CI checks. Under Connect Buildkite, enter the organization slug, the pipeline slug (api) and the API token, then choose Connect.

GitStack shows three values. Copy all three now, since the fetch token is shown only once:

  • Webhook URL, https://gitstack.sh/hooks/buildkite/<id>
  • Signing secret
  • Fetch token, which starts with gsi_

5. Store the fetch token in Buildkite#

In Buildkite, open Agents, then the cluster your hosted agents run in, then Secrets. Add a secret named GITSTACK_FETCH_TOKEN with the fetch token as its value, and give it an access policy that names the api pipeline. The env block reads it whenever git asks for a password, so the token never shows in a build's environment or log.

6. Add the webhook in Buildkite#

In Buildkite, open Settings, then Notification Services, and add a Webhook with these settings:

Setting Value
Webhook URL The webhook URL from GitStack
Token The signing secret from GitStack
Token mode Send the token as X-Buildkite-Signature
Events build.scheduled, build.running, build.failing, build.finished, build.skipped, job.started, job.finished
Pipelines api
Setting
Webhook URL
Value
The webhook URL from GitStack
Setting
Token
Value
The signing secret from GitStack
Setting
Token mode
Value
Send the token as X-Buildkite-Signature
Setting
Events
Value
build.scheduled, build.running, build.failing, build.finished, build.skipped, job.started, job.finished
Setting
Pipelines
Value
api

7. Require the checks#

Add the checks to the repository's landing policy. [checks] makes landing wait for the two steps. [ci] is optional: it builds new tags that match v*, for a release step.

toml
# .gitstack/policy.toml
[checks]
required = ["buildkite:api/lint", "buildkite:api/test"]

[ci]
tags = ["v*"]

The buildkite: prefix pins each check to Buildkite, so no other CI service can satisfy it. Land the policy as a review. The policy that applies to a land is the one already on the default branch, so this land doesn't wait for the checks it adds:

bash
gs switch -c require-ci
gs add .gitstack/policy.toml
gs commit -m "policy: require the Buildkite checks" --review -t "policy: require the Buildkite checks"
gs submit

8. Land a change#

Make any change and submit it:

bash
gs switch -c first-build
gs add README.md
gs commit -m "docs: say how to run the tests" --review -t "docs: say how to run the tests"
gs submit

What success looks like#

gs submit sees that the checks haven't run on the review's commit, asks Buildkite to build it, and waits:

text
checks started on R12 (a1b2c3d); waiting for buildkite:api/lint, buildkite:api/test (Ctrl-C to stop)

In Buildkite, a new build of the api pipeline appears for that commit, with GITSTACK_EVENT=review in its environment. When both steps pass, gs submit lands the review:

text
submitted R12 → main 9f3e2d1c4b5a6d7e8f90a1b2c3d4e5f6a7b8c9d0

On the review page, the required checks row shows both checks passing, each linked to its Buildkite job. Right after the land, Buildkite builds the new tip of main (GITSTACK_EVENT=main). If that build fails a required check, GitStack retries the failed jobs once and reverts the land when they fail again (see When the default branch goes red).

In Settings, CI checks, the integration's status reads ok once the first webhook delivery arrives. If it still reads no deliveries, check the webhook's URL, token and token mode. If a build fails to clone, check the secret's name and its access policy, and that the pipeline's own steps carry the env block.

Next#

  • CI with Buildkite: your own agents, retries and cancels, what happens when the default branch goes red, and what each Buildkite state means.
  • Moving from GitHub Actions: switch an existing repository over without a gap in its required checks.
  • CI with any builder: connect a builder GitStack has no connector for.