Skip to content
Latchkey

bazel run Command Reference

Build a runnable target and execute it in one command.

bazel run builds an executable target and then runs it. CI uses it for deploy rules, code generators, and tools defined inside the repo.

What it does

bazel run builds a runnable target (binary, deploy rule, or tool) and executes it in a runfiles environment. Arguments after a -- separator are passed to the program, not to Bazel.

Common flags and usage

  • //path:target: the runnable target to build and execute
  • -- <args>: arguments forwarded to the program
  • --config=NAME: apply a named config from .bazelrc
  • --run_under=CMD: wrap execution (for example a debugger)

Example

shell
- name: Run deploy target
  run: bazel run --config=ci //deploy:push -- --env=staging

In CI

Use bazel run for in-repo tools and deploy rules so the same hermetic build feeds the action. Always place program arguments after -- so Bazel does not interpret them as its own flags.

Key takeaways

  • bazel run builds then executes a runnable target.
  • Arguments after -- go to the program, not to Bazel.
  • Ideal for in-repo deploy rules, codegen, and tools.

Related guides

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