Jenkins+Gitlab 代码自动审查
我们在做codereview时, 往往需要定期主动去检查开发人员的代码. 这个步骤相对繁琐, 也容易忘记. 我们可以用jenkins+gitlab实现代码自动审查的工作
- Jenkins集成checkstyle
系统管理->插件管理->可选插件, 搜索并安装checkstyle插件

- Jenkins集成findbugs
系统管理->插件管理->可选插件, 搜索并安装findbugs插件

- Jenkins任务配置
新建一个"自由风格的软件项目"
源码管理: 配置Git代码地址
构建触发器: Build when a change is pushed to GitLab. GitLab webhook URL: http://XXX

构建: mvn clean compile -DskipTests=true checkstyle:checkstyle findbugs:findbugs

构建后操作:
Publish Checkstyle analysis results
Checkstyle results: **/checkstyle-result.xml
Publish FindBugs analysis results
FindBugs results: **/findbugsXml.xml

- Gitlab配置webhook钩子
将上面"构建触发器"的http://XXX地址配置到gitlab中
settings -> Integrations
URL: http://XXX
Add webhook
这样就完成了相关配置
当项目代码提交并push时, gitlab的webhook会触发Jenkins的构建任务;
Jenkins构建, 并执行maven, 然后将checkstyle和findbugs的结果输出到checkstyle-result.xml和findbugsXml.xml


- 如果需要定义checkstyle.xml, 则需要在代码的pom.xml加入如下配置(project>build>plugins):
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.1.1</version>
<configuration>
<configLocation>custom_checks.xml</configLocation>
</configuration>
</plugin>
custom_checks.xml 也必须放在代码中