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=stagingIn 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
bazel build Command ReferenceReference for bazel build in CI/CD: build targets and patterns hermetically, scope with target syntax, and ac…
bazel test Command ReferenceReference for bazel test in CI/CD: run test targets with caching, surface failing logs with --test_output=err…
bazel query Command ReferenceReference for bazel query in CI/CD: inspect the dependency graph to find reverse deps, scope affected targets…