Toolkit: CI, BuildBuddy & Affected Targets
Running bazel test //... on every commit is correct and, thanks to caching, often affordable. At scale, CI pipelines add three things: build event data (what happened, for dashboards and flaky-test tracking), affected-target computation (build and test only what a change can influence) and a results UI.
The Build Event Protocol
Every Bazel command emits a stream of build events: started, options, targets configured, actions, test results, build finished. You can write it to a file or stream it to a server:
| Flag | Destination |
|---|---|
--build_event_json_file=bep.json |
newline-delimited JSON, for scripts |
--build_event_binary_file=bep.pb |
protobuf, compact |
--bes_backend=grpcs://remote.buildbuddy.io + --bes_results_url=… |
a Build Event Service: BuildBuddy, EngFlow, Buildbarn's bb-portal… |
bash · try it yourself
mkdir ws && cd ws
echo 'bazel_dep(name = "rules_python", version = "2.4.5")' > MODULE.bazel
mkdir -p t
cat > t/BUILD.bazel <<'EOF'
load("@rules_python//python:defs.bzl", "py_test")
py_test(name = "good_test", size = "small", srcs = ["good_test.py"])
py_test(name = "bad_test", size = "small", srcs = ["bad_test.py"])
EOF
echo 'print("fine")' > t/good_test.py
echo 'raise SystemExit("broken")' > t/bad_test.py
bazel test //t:all --build_event_json_file=bep.json >/dev/null 2>&1
echo "exit code: $?"
echo "== event kinds"
jq -r '.id | keys[0]' bep.json | grep -v '^progress