Bad code style is considered unsuccessful by Jenkins / checkstyle

I use Jenkins to test a Java software project (using a web playback platform, but that doesn't really matter).

Part of the test is about the code style for which I use checkstyle. I tried to set up my work as follows:

  • I execute checkstyle through the command line that generates a report in xml

checkstyle -c /usr/share/checkstyle/sun_checks.xml -f xml -r app test -o checkstyle.xml

  • Then I add a post-build action using this Jenkins plugin that reads the xml report and integrates into the build results

So now my problem is this: when there are any style issues in the code, Jenkins considers the job to be a failure. By default, the post-build action is not executed in this case.

You can change this so that the report is generated, however, although it still causes me an error that a bad code style is considered a failure. I think this is subjective. Anyway, is there a way to change this? And in general, how does Jenkins determine if the command shell is unsuccessful?

+4
source share
1 answer

If you look at the source code of the Main checkstyle class ( link ), you will see that the exit code is the number of style problems found (or 1 in some exceptional cases).

This is what Jenkins pays attention to: an exit code from 0 canonically indicates success, and a nonzero code indicates failure.

I think your solution is to make exit code 0 unconditionally. Team A (bash) for this will be

 checkstyle <arguments...> || true 

More generally, you can write a small wrapper script that will run checkstyle and then exit with code 0.

+4
source

All Articles