Skip to content

Buildkite

Selective detects Buildkite automatically. The build, branch, commit, retry count and parallel job index all come from Buildkite’s environment, so a retried job and a fresh build are told apart correctly.

Provide SELECTIVE_API_KEY to the step through your secrets mechanism, then swap the command:

steps:
- label: tests
command: bundle exec selective rspec
parallelism: 4

parallelism is the node count. Each parallel job connects to Selective as one node of the same run.

Test selection needs a fresh map of which files each test executes. In the pipeline’s Settings → Schedules, add a daily schedule on the default branch with this environment variable:

SELECTIVE_TEST_MAP_RECORD=1

The scheduled build runs the same steps, and its test step prints Recording a test map. See keeping the map fresh.

With test selection on, a step that tells Selective about the build as it starts has the commit’s file tree, the map and the semantic decision ready before the test nodes connect. See warm-up.

steps:
- label: selective warm-up
soft_fail: true
command: |
curl -sS --max-time 20 -X POST https://app.selective.ci/warmup \
-H "authorization: $$SELECTIVE_API_KEY" -H "content-type: application/json" \
-d "{\"sha\": \"$$BUILDKITE_COMMIT\", \"git_repo_full_name\": \"acme/shop\", \"target_branch\": \"$$BUILDKITE_PULL_REQUEST_BASE_BRANCH\", \"branch\": \"$$BUILDKITE_BRANCH\"}" \
|| true
- label: tests
command: bundle exec selective rspec
parallelism: 4

There’s no wait between the steps, so they start together. The $$ defers the variables to when the step runs; with a single $, Buildkite interpolates them when the pipeline is uploaded, which would write the API key into the pipeline. There’s no base_sha because the runner doesn’t report one on Buildkite.