Skip to content
Latchkey

bazel Command: Build Monorepos in CI

bazel builds and tests large multi-language codebases hermetically and cached.

Bazel is Google's hermetic, content-addressed build system, used for large polyglot monorepos. In CI its remote caching and incremental graph make builds reproducible and fast, at the cost of a steeper configuration model (BUILD files and a module/workspace).

Common flags

  • bazel build //... - build all targets (//path:target for one)
  • bazel test //... - build and run all test targets
  • --config=ci - apply a named config group from .bazelrc
  • --remote_cache=URL - read/write a remote build cache
  • --keep_going / -k - keep building after a failure
  • --test_output=errors - print logs only for failing tests
  • --jobs=N - limit concurrent actions

Example in CI

Run all tests with a CI config and a shared remote cache:

shell
bazel test //... --config=ci --remote_cache=\${BAZEL_CACHE_URL} --test_output=errors

Common errors in CI

  • ERROR: no such package 'X': BUILD file not found - missing or wrong package path
  • ERROR: no such target '//a:b' - target name not defined in the BUILD file
  • ERROR: Error loading package - Starlark/.bzl load or syntax error
  • ERROR: Remote Cache: failed to download ... - cache backend connectivity issue

Key takeaways

  • Use //... to build/test everything; a remote cache makes CI fast.
  • --config=ci centralizes CI-specific flags in .bazelrc.
  • Most failures are "no such package/target" from BUILD-file path mismatches.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →