buildkite-preflight
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseBuildkite Preflight
Buildkite Preflight
Preflight runs CI builds against changes in the local working directory. 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.
Preflight 针对本地工作目录的变更运行CI构建。它旨在通过提供单一命令来完成整个提交/推送/运行流程,为在CI中评估本地变更提供反馈循环。
When to Run Preflight
何时运行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
- 完成要求的实现且本地测试通过后,使用preflight在CI上运行整个测试套件
- 在长时间无人值守的会话结束前,若已进行多项变更
- 修复上一次preflight运行的失败后
- 除非用户要求,否则不要针对拼写错误、仅注释编辑或单行配置调整等微小变更运行
- 当用户要求验证变更在CI中是否正常工作时
Before Running
运行前准备
- Prefer an explicit pipeline in form
{org}/{pipeline} - Ensure is pointed at the right Buildkite organization when the pipeline slug relies on local config
bk auth - Requires a git repository with at least one commit and push access to
origin - Requires ,
read_builds, andwrite_buildsscopes; andread_pipelinesfor Test Engine results.read_suites - Run preflight in a subagent
- 优先使用格式的显式流水线
{org}/{pipeline} - 当流水线slug依赖本地配置时,确保指向正确的Buildkite组织
bk auth - 需要一个至少有一次提交且拥有推送权限的git仓库
origin - 需要、
read_builds和write_builds权限范围;若要获取Test Engine结果,还需要read_pipelines权限read_suites - 在子agent中运行preflight
Running Preflight
运行Preflight
bash
undefinedbash
undefinedHuman-readable output that works well in agent shells
Human-readable output that works well in agent shells
bk preflight --pipeline my-org/my-pipeline --watch --text
bk preflight --pipeline my-org/my-pipeline --watch --text
Start a run and return as soon as the build enters the failing state
Start a run and return as soon as the build enters the failing state
bk preflight --pipeline my-org/my-pipeline --watch
bk preflight --pipeline my-org/my-pipeline --watch
Wait for a terminal build state instead of fast-failing
Wait for a terminal build state instead of fast-failing
bk preflight --pipeline my-org/my-pipeline --watch --exit-on=build-terminal
bk preflight --pipeline my-org/my-pipeline --watch --exit-on=build-terminal
Start the build and exit immediately
Start the build and exit immediately
bk preflight --pipeline my-org/my-pipeline --no-watch
bk preflight --pipeline my-org/my-pipeline --no-watch
Leave the remote preflight branch and build running on early exit
Leave the remote preflight branch and build running on early exit
bk preflight --pipeline my-org/my-pipeline --watch --no-cleanup
bk preflight --pipeline my-org/my-pipeline --watch --no-cleanup
Wait for 30s after build completion for Test Engine summaries
Wait for 30s after build completion for Test Engine summaries
bk preflight --pipeline my-org/my-pipeline --watch --await-test-results 30s
Do not set a timeout on a watched preflight run.bk preflight --pipeline my-org/my-pipeline --watch --await-test-results 30s
不要为处于监控状态的preflight运行设置超时。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 , even when the tree is clean, so the run has its own commit status context.
HEAD - Push - Pushes that commit to on
refs/heads/bk/preflight/<uuid>.origin - Create Build - Calls the Buildkite Create Build API and sets ,
PREFLIGHT=true, andPREFLIGHT_SOURCE_COMMITwhen available.PREFLIGHT_SOURCE_BRANCH - 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 is set. With the default
--no-cleanup, early exit also cancels the remote build unless--exit-on=build-failingis set.--no-cleanup
The working tree is never disrupted, so you can keep editing while the build runs.
Preflight 执行以下工作流程:
- 快照 - 使用临时git索引捕获已暂存、未暂存和未跟踪的文件,不会修改真实索引或工作区。
- 提交 - 在之上创建一个独立的preflight提交,即使工作区已清理,这样运行会有自己的提交状态上下文。
HEAD - 推送 - 将该提交推送到的
origin分支。refs/heads/bk/preflight/<uuid> - 创建构建 - 调用Buildkite创建构建API,并在可用时设置、
PREFLIGHT=true和PREFLIGHT_SOURCE_COMMIT环境变量。PREFLIGHT_SOURCE_BRANCH - 监控 - 监控构建并输出操作事件、构建状态更新、任务失败、重试通过的任务以及最终摘要。
- 清理 - 运行结束后删除远程preflight分支,除非设置了。默认
--no-cleanup情况下,提前退出也会取消远程构建,除非设置了--exit-on=build-failing。--no-cleanup
工作区永远不会被干扰,因此你可以在构建运行时继续编辑文件。
Reading the Result
查看结果
- The default exit policy is , so the preflight command exits as soon as the build enters the
build-failingstate.failing - waits for a terminal build state (passed, failed, canceled).
--exit-on=build-terminal - waits after build completion for Test Engine rollups when test runs exist.
--await-test-results - 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 to inspect logs.
bk job log -b <build-number> -p <org>/<pipeline> <job-id> - 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:
Just the failed jobs from the summary:
bk preflight --pipeline my-org/my-pipeline --watch --json \
| jq -nrc --unbuffered 'inputs | select(.type == "build_summary") | .failed_jobs'
Just the failed tests from the summary:
bk preflight --pipeline my-org/my-pipeline --watch --json \
| jq -nrc --unbuffered 'inputs | select(.type == "build_summary") | .tests.failures'- 默认退出策略为,因此preflight命令会在构建进入
build-failing状态时立即退出。failing - 会等待构建进入终端状态(通过、失败、取消)。
--exit-on=build-terminal - 会在构建完成后等待Test Engine的汇总结果(如果存在测试运行)。
--await-test-results - 最终任务摘要涵盖硬失败的脚本任务,排除非脚本、中断和软失败的任务
- 失败任务的输出包含任务ID。使用查看日志。
bk job log -b <build-number> -p <org>/<pipeline> <job-id> - 当有分析数据可用时,最终摘要会显示每个测试套件的通过/失败/跳过数量,以及最多10个失败测试。
- 测试失败会包含测试名称和位置;在本地重现失败并修复。
- 如果失败是不稳定的或与你的变更无关,请告知用户,而非尝试修复。
从JSON build_summary事件中提取结果:
Just the failed jobs from the summary:
bk preflight --pipeline my-org/my-pipeline --watch --json \
| jq -nrc --unbuffered 'inputs | select(.type == "build_summary") | .failed_jobs'
Just the failed tests from the summary:
bk preflight --pipeline my-org/my-pipeline --watch --json \
| jq -nrc --unbuffered 'inputs | select(.type == "build_summary") | .tests.failures'Output Modes
输出模式
- Use for plain text logs that are easy to read in tool output
--text - Use when you need structured event data
--json - If neither flag is set, uses the interactive TTY UI when stdout is a terminal and plain text otherwise
bk
- 使用获取纯文本日志,便于在工具输出中阅读
--text - 需要结构化事件数据时使用
--json - 如果未设置任何标志,当stdout是终端时会使用交互式TTY UI,否则使用纯文本
bk
Running a Preflight Build
运行Preflight构建
Basic usage
基础用法
bash
undefinedbash
undefinedRun preflight and watch until completion
Run preflight and watch until completion
bk preflight --pipeline my-org/my-pipeline --watch
bk preflight --pipeline my-org/my-pipeline --watch
Run without watching (starts the build and exits)
Run without watching (starts the build and exits)
bk preflight --pipeline my-org/my-pipeline --no-watch
bk preflight --pipeline my-org/my-pipeline --no-watch
Skip confirmation prompts (useful in scripts)
Skip confirmation prompts (useful in scripts)
bk preflight --pipeline my-org/my-pipeline --watch --yes
bk preflight --pipeline my-org/my-pipeline --watch --yes
Keep the remote preflight branch after the build finishes
Keep the remote preflight branch after the build finishes
bk preflight --pipeline my-org/my-pipeline --watch --no-cleanup
bk preflight --pipeline my-org/my-pipeline --watch --no-cleanup
Use plain text output in non-interactive environments
Use plain text output in non-interactive environments
bk preflight --pipeline my-org/my-pipeline --watch --text
bk preflight --pipeline my-org/my-pipeline --watch --text
Use JSONL output when another tool needs structured events
Use JSONL output when another tool needs structured events
bk preflight --pipeline my-org/my-pipeline --watch --json
bk preflight --pipeline my-org/my-pipeline --watch --json
Wait for 10s for Test Engine results after build completion
Wait for 10s for Test Engine results after build completion
bk preflight --pipeline my-org/my-pipeline --watch --await-test-results 10s
Do not set a timeout on the bash tool running preflight.bk preflight --pipeline my-org/my-pipeline --watch --await-test-results 10s
不要为运行preflight的bash工具设置超时。Pipeline resolution
流水线解析
The flag accepts either a pipeline slug or :
--pipeline{org slug}/{pipeline slug}bash
undefined--pipeline{org slug}/{pipeline slug}bash
undefinedWith org prefix (explicit)
With org prefix (explicit)
bk preflight --pipeline my-org/my-pipeline --watch
bk preflight --pipeline my-org/my-pipeline --watch
Pipeline slug only (org resolved from bk config)
Pipeline slug only (org resolved from bk config)
bk preflight --pipeline my-pipeline --watch
undefinedbk preflight --pipeline my-pipeline --watch
undefinedFlags
标志
| Flag | Short | Default | Description |
|---|---|---|---|
| | - | Pipeline to build ( |
| - | Watch the build until completion | |
| | Exit on | |
| | Polling interval in seconds when watching | |
| | Skip deleting the remote preflight branch after the build finishes | |
| Wait for Test Engine summaries after build completion | ||
| | Use plain text output instead of the interactive UI | |
| | Emit one JSON object per event (JSONL) | |
| | | Skip all confirmation prompts |
| | Disable all interactive prompts | |
| | | Suppress progress output |
| | Disable pager for text output | |
| | Enable debug output for REST API calls |
| Flag | Short | Default | Description |
|---|---|---|---|
| | - | 要构建的流水线( |
| - | 监控构建直至完成 | |
| | 在 | |
| | 监控时的轮询间隔(秒) | |
| | 构建完成后跳过删除远程preflight分支 | |
| 构建完成后等待Test Engine汇总结果 | ||
| | 使用纯文本输出替代交互式UI | |
| | 每个事件输出一个JSON对象(JSONL格式) | |
| | | 跳过所有确认提示 |
| | 禁用所有交互式提示 | |
| | | 抑制进度输出 |
| | 禁用文本输出的分页器 | |
| | 启用REST API调用的调试输出 |
Exit Codes
退出码
Check the exit code to determine the build result:
| Exit Code | Meaning | Action |
|---|---|---|
| All command jobs passed | Proceed with commit/push |
| Generic error | Check error message for details |
| Build completed with failures | Examine failed jobs and fix |
| Build incomplete but failures observed | Build still running; failures already detected |
| Build incomplete (scheduled/running/blocked) | Build hasn't finished yet |
| Unknown build state | Investigate the build on Buildkite |
| User aborted (Ctrl+C) | Re-run when ready |
通过检查退出码判断构建结果:
| Exit Code | Meaning | Action |
|---|---|---|
| 所有命令任务均通过 | 继续执行提交/推送 |
| 通用错误 | 查看错误消息了解详情 |
| 构建完成但存在失败 | 检查失败任务并修复 |
| 构建未完成但已发现失败 | 构建仍在运行;已检测到失败 |
| 构建未完成(已调度/运行中/被阻塞) | 构建尚未结束 |
| 未知构建状态 | 在Buildkite上调查该构建 |
| 用户中止(Ctrl+C) | 准备就绪后重新运行 |
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, and then check back on the same build with for subsequent failures. This allows you to quickly iterate on the first failure, and gather further failures in parallel. Use the option to ensure that build is not cancled on fast failure.
bk build viewbk preflight --no-cleanupbash
bk preflight --pipeline my-org/my-pipeline --watch --no-cleanup --textbk preflightfailing--exit-on=build-failing--no-cleanupWorkflow:
- 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.
- Use to check the same build again while it continues running:
bk build view
bash
bk build view <build-number> -p my-org/my-pipeline --text- After the build reaches a terminal state and you no longer need the remote preflight branch, clean it up explicitly:
bash
bk preflight cleanup --pipeline my-org/my-pipeline --preflight-uuid <uuid> --yes --textbk preflight cleanup当preflight因构建未完成且已失败而退出时,立即开始修复第一个失败,因为构建已处于失败状态,之后使用复查同一构建的后续失败。这让你可以快速迭代修复第一个失败,同时并行收集更多失败。使用选项确保构建在快速失败时不会被取消。
bk build viewbk preflight --no-cleanupbash
bk preflight --pipeline my-org/my-pipeline --watch --no-cleanup --textbk preflightfailing--exit-on=build-failing--no-cleanup工作流:
- 等待preflight在构建失败时退出(默认条件)。
--exit-on - 检查失败构建的任务日志和测试失败,立即开始修复问题。
- 记录运行输出中的构建编号或preflight UUID。
- 使用在构建继续运行时复查同一构建:
bk build view
bash
bk build view <build-number> -p my-org/my-pipeline --text- 当构建进入终端状态且不再需要远程preflight分支时,显式清理:
bash
bk preflight cleanup --pipeline my-org/my-pipeline --preflight-uuid <uuid> --yes --textbk preflight cleanup