| name | buildbuddy_api |
| description | Reference for querying BuildBuddy API. Use when investigating failed or slow CI builds, inspecting invocations by commit or branch, reading build or test logs, checking remote execution (RBE) details (exit codes, stderr, worker logs), analyzing cache hit/miss rates, downloading undeclared test outputs from RBE workers, bisecting test failures using target history to find the culprit commit range, viewing aggregated build statistics, triggering workflow re-runs, or getting AI analysis of build failures. Trigger when the user asks "why did this build fail", "show me the build log", "check RBE execution", "get test output from RBE", "what happened in this CI run", "check cache performance", "when did this test start failing", "find the commit that broke this test", "re-run CI", "trigger a workflow", "build stats by branch", "ask BuildBuddy about this failure", or any task that requires fetching data from BuildBuddy.
|
BuildBuddy API
Prerequisites
All commands require BUILDBUDDY_API_KEY to be set (session hook exports it automatically).
Official bb CLI
The official BuildBuddy CLI (bb) handles build logs and execution details:
bb view <invocation-id-or-url> [--lines=100000]
bb execution get <execution-id> [--output=json]
bb download <digest>/<size> [--type=Action|Command]
bbapi CLI
bbapi provides API query features not available in bb:
bbapi invocation <invocation-id>
bbapi invocation list [--repo URL] [--count N]
bbapi target log <invocation-id> <target-label-or-substring>
bbapi target <invocation-id> [--filter SUBSTR] [--label LABEL]
bbapi target history [--repo URL] [--label LABEL] [--failures-only]
bbapi target stats [--repo URL]
bbapi target flakes <target-label> [--repo URL]
bbapi artifact <invocation-id> [name-substring]
bbapi execution <invocation-id>
bbapi execution search <query>
bbapi invocation stat [--agg-type branch|user|host|repo|commit|pattern] [--repo URL] [--limit N]
bbapi ask <invocation-id> [--prompt TEXT]
bbapi workflow
bbapi workflow run [--workflow-id ID] [--branch BRANCH] [--commit SHA] [--action NAME] [--async]
bbapi cache <invocation-id>
bbapi cache metadata <digest> <size-bytes>
bbapi trend [--days N] [--repo URL]
All bbapi commands support --json for raw JSON output.
Investigating Failed CI Builds
Typical workflow for debugging a failed CI build:
bbapi invocation <invocation-id>
bb view <invocation-id>
bbapi target log <invocation-id> <target-substring>
Workflow vs Child Invocations
BuildBuddy CI runs use workflow invocations that spawn child invocations.
The workflow invocation (command: workflow run) is a wrapper; the child
invocation contains the actual bazel test results, targets, and artifacts.
bbapi invocation shows Child: <child-id> for workflow invocations
bbapi artifact and bbapi target log auto-resolve workflow invocations
to their children — you can pass either the workflow or child ID
bbapi target also auto-resolves workflow invocations to their children
Artifact Name Matching
bbapi artifact and bbapi target log match against "label/name":
"test_handlers" matches //x/gatelet/server/auth:test_handlers/test.log
"test_handlers/test.xml" matches the XML output specifically
"compositor/test_lifecycle" matches //mcp_infra/compositor:test_lifecycle/test.log
When no match is found, the CLI prints available labels as hints.
Bisecting Test Failures with Target History
When a test is failing and you need to find the commit that broke it, use target
history instead of git bisect — BuildBuddy already has all the results:
bbapi target history --failures-only --label //path/to:test_target
git log --oneline <last-pass-commit>..<first-fail-commit>
bbapi target log <first-failing-invocation-id> test_target
This is much faster than git bisect because it doesn't require re-running the
test — the results are already in BuildBuddy's database.
Diagnosing Executor Environments
Use bb execute to run one-off commands directly on a BuildBuddy executor to probe the container image, check installed tools, verify library paths, etc. Useful when builds fail due to missing dependencies or environment issues.
bb execute \
-exec_properties=container-image=docker://ghcr.io/agentydragon/rbe-worker:nix-devtools \
-- bash -c 'gcc --version; python3 --version; ldd --version | head -1'
bb execute \
-exec_properties=container-image=docker://ghcr.io/agentydragon/rbe-worker:latest \
-- bash -c 'find / -name "libstdc++.so*" 2>/dev/null'
bb execute \
-exec_properties=container-image=docker://ghcr.io/agentydragon/rbe-worker:latest \
-- bash -c 'python3 -m pip install --dry-run some-package==1.0'
bb execute runs on the default executor image (Ubuntu 16.04, glibc 2.23) unless you specify -exec_properties=container-image=.... Use -exec_properties=workload-isolation-type=firecracker to test with Firecracker isolation.
Interactive debugging with bb ssh
For interactive debugging, start an SSH server on a BuildBuddy executor:
bb ssh-server my-debug-session
bb ssh my-debug-session
This gives a full shell on the executor for investigating build failures, inspecting the filesystem, testing commands interactively, etc.
BuildBuddy Concepts
Group ID: BuildBuddy's organization identifier (e.g., GR7963402054611859571).
Scopes API queries to the org's data. Auto-detected by bbapi from a recent invocation's
ACL — no manual configuration needed.
Workflow ID: For repos using buildbuddy.yaml + GitHub app, workflow IDs are synthetic:
WF#GitRepository:{group_id}:{repo_url}. The bbapi workflow run command auto-constructs
this from the detected group_id and repo URL. GetWorkflows returns empty for these repos
(it only lists explicitly created workflows).
Raw API Fallback
If bbapi is not available, use the Twirp JSON API at app.buildbuddy.io directly
with curl. Read <devinfra/buildbuddy_cli/client.go> for how the CLI talks to the API
(Twirp JSON over HTTP). The API key comes from BUILDBUDDY_API_KEY env var, or
parse it from ~/.config/bazel/buildbuddy.bazelrc (x-buildbuddy-api-key=...).
Proto definitions for request/response schemas:
Known Limitations
Fork PRs don't have BuildBuddy invocations. GitHub Actions does not pass
BUILDBUDDY_API_KEY to workflows triggered by fork pull requests (head repo !=
base repo). As a result, bazel-check and bazel-test are skipped entirely on
fork PRs (see #787).
When investigating a failed fork PR, BuildBuddy has no record of the run — check
GitHub Actions logs directly instead.