bazel build Command Reference
Build Bazel targets hermetically, with caching that scales across runners.
bazel build builds one or more targets using Bazel hermetic, content-addressed model. In CI its remote cache turns repeated builds into near-instant cache hits.
What it does
bazel build analyzes the dependency graph for the requested target patterns and builds them, reusing cached action outputs whenever inputs are unchanged. Targets use //package:target syntax, with //... meaning everything under a path.
Common flags and usage
- //path/to:target or //...: target patterns to build
- --config=NAME: apply a named config from .bazelrc
- --remote_cache=URL: use a shared remote cache
- --jobs=N: cap concurrent actions
- --keep_going / -k: build as much as possible after a failure
Example
- name: Build everything
run: bazel build --config=ci //...In CI
Put --remote_cache and shared flags in a ci config in .bazelrc and select it with --config=ci, so warm caches make most CI builds cache hits. Latchkey managed runners can point Bazel at a persistent remote cache so builds stay warm across jobs.
Key takeaways
- bazel build is hermetic and reuses cached action outputs by content hash.
- Target patterns use //package:target syntax; //... means everything.
- A shared --remote_cache makes most CI builds cache hits.