Buildkite Preflight
Preflight runs CI builds against changes in the local working tree. It's intended to provide a feedback loop for evaluating local changes in CI by providing a single command to run the entire commit/push/run loop.
When to Run Preflight
- After completing the requested implementation and local tests pass, use preflight to run the whole test suite on CI
- Before a long unsupervised session ends if you've made multiple changes
- After fixing a failure from a previous preflight run
- Not for trivial changes like typos, comment-only edits, or single-line config tweaks unless the user asks
- When the user asks to verify changes work in CI
Before Running
- Prefer an explicit pipeline in
{org}/{pipeline}form - Ensure
bk authis pointed at the right Buildkite organization when the pipeline slug relies on local config - Requires a git repository with at least one commit and push access to
origin - Requires
read_builds,write_builds, andread_pipelinesscopes; andread_suitesfor Test Engine results. - Run preflight in a subagent
Running Preflight
Do not set a timeout on a watched preflight run.
How It Works
Preflight executes the following workflow:
- Snapshot - Captures staged, unstaged, and untracked files using a temporary git index, without modifying the real index or working tree.
- Commit - Creates a distinct preflight commit on top of
HEAD, even when the tree is clean, so the run has its own commit status context. - Push - Pushes that commit to
refs/heads/bk/preflight/<uuid>onorigin. - Create Build - Calls the Buildkite Create Build API and sets
PREFLIGHT=true,PREFLIGHT_SOURCE_COMMIT, andPREFLIGHT_SOURCE_BRANCHwhen available. - Monitor - Watches the build and emits operation events, build status updates, job failures, retry-passed jobs, and a final summary.
- Cleanup - Deletes the remote preflight branch when the run finishes unless
--no-cleanupis set. With the default--exit-on=build-failing, early exit also cancels the remote build unless--no-cleanupis set.
The working tree is never disrupted, so you can keep editing while the build runs.
Reading the Result
- The default exit policy is
build-failing, so the preflight command exits as soon as the build enters thefailingstate. --exit-on=build-terminalwaits for a terminal build state (passed, failed, canceled).--await-test-resultswaits after build completion for Test Engine rollups when test runs exist.- Final job summaries cover hard-failed script jobs and exclude non-script, broken, and soft-failed jobs
- Failed job output includes the job id. Use
bk job log -b <build-number> -p <org>/<pipeline> <job-id>to inspect logs. - When analytics are available, the final summary shows per-suite passed/failed/skipped counts and up to 10 failed tests.
- Test failures include the test name and location; reproduce the failure locally and fix it.
- If a failure is flaky/unrelated to your changes, note it to the user rather than trying to fix it.
Extracting results from the JSON build_summary event:
Output Modes
- Use
--textfor plain text logs that are easy to read in tool output - Use
--jsonwhen you need structured event data - If neither flag is set,
bkuses the interactive TTY UI when stdout is a terminal and plain text otherwise
Running a Preflight Build
Basic usage
Do not set a timeout on the bash tool running preflight.
Pipeline resolution
The --pipeline flag accepts either a pipeline slug or {org slug}/{pipeline slug}:
Flags
Exit Codes
Check the exit code to determine the build result:
Further Reading
Optional Workflow: Act On A Failure And Check Back Later
Begin fixing the first failure as soon as preflight exits with an incomplete build result because the build is failing. Check the same build's summary while it continues, then query failed jobs directly for subsequent failures. This allows you to quickly iterate on the first failure, and gather further failures in parallel. Use the bk preflight --no-cleanup option to ensure that build is not canceled on fast failure.
bk preflight will return as soon as the build transitions to failing, using the default --exit-on=build-failing behavior. Setting the --no-cleanup flag is required if you want the build to continue running to completion.
Workflow:
- Wait for preflight to exit on build failing (the default --exit-on condition).
- Inspect the failed build's jobs logs and test failures and start fixing the issue immediately.
- Keep the build number or preflight UUID from the run output.
- Check the build state without downloading jobs, artifacts, annotations, or expanded pipeline details. Query failed jobs separately through the REST List Jobs endpoint:
- After the build reaches a terminal state and you no longer need the remote preflight branch, clean it up explicitly:
bk preflight cleanup only deletes completed preflight branches, so run it after the build has finished.


