Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Findbugs for Git Pull Request

Is there a way to setup Findbugs (or any other static code analysis tool) in Jenkins to analyse the incoming pull requests and compare the result with the main branch? My goal is to reject pull requests which increase the number of static code analysis issues.

like image 816
Malik Atalla Avatar asked Sep 04 '14 22:09

Malik Atalla


Video Answer


1 Answers

You can realize your idea by using the Maven-plugins checkstyle, findbugs and pmd (-cpd).

Each of this plugin has a ":check"-mojo, which can fail the build - based on zero or configured rule-violations.

  • checkstyle check-mojo
  • findbugs check-mojo
  • pmd check-mojo
  • pmd-cpd check-mojo

This mojos are bound to the maven-"verify"-phase, so mvn verify will do the job - or you execute the mojos directly within your jenkins-build (job-configuration "Build" -> "Goals and options" -> mvn verfiy, or mvn test checkstyle:check).

The plugins have different ways to configure a fail.

For example, checkstyle-plugin has maxAllowedViolations-configuration-parameter. So you can set this parameter to your current violations-count, and use mvn verfiy or mvn checkstyle:check to let your build fail, if a new violation occurs. Of course, you would have to increase this parameter every time a checkstyle-violation is fixed.

In fingbugs-plugin, your build would have to be free of violations, before you can use mvn findbugs:check.

like image 126
Markus Schulte Avatar answered Oct 08 '22 12:10

Markus Schulte