Bazel Build Command – Is possible to skip "Test" Targets and Rules?


I wish to run bazel build :...all command and skip test rules and targets. Is this possible?

I can conceive of two ways to distinguish the tests, either by their type (cc_test in my case), or by pattern-matching on the name, as the project I’m working in suffixes all test rules/targets with “_test”.

Please, refrain from making comments telling me that I should always build and run tests upon compilation, unless Bazel actually makes it technically impossible to use “all” wildcard and also filter out all tests. We have a tiered system where builds and tests are all run together, and then after success, another system just builds the minimum artifacts.


There is bazel query. It’s quite powerful so I advise to read through the documentation page to design the query command precisely. To quickly answer your concrete question, I think this will work for you:

bazel query '//... except kind(.*test, //...)' | xargs bazel build

Answered By – hlopko

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published