Jenkins系列之六整合SonarQube,深度剖析原理

??SonarQube作为一款代码质量检测工具,在实际开发的过程中对于作为代码门禁检查是非常有必要的。在Jenkins整合SonarQube之前,环境上需要先安装SonarQube软件,SonarQubu的安装很简单,但是安装的过程中会有各种各样奇葩的问题,解决方案:Centos7安装SonarQube常见问题。

一、插件安装

??Jenkins整合SonarQube也很简单,需要安装一个SonarQube Scanner的插件,插件的具体安装步骤参考:Jenkins系列之二插件安装及权限设置。 Jenkins与SonarQube的调用关系如下所示:

mermaid-svg-vyCVzqqN1Tkh9fbL .label{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);fill:#333;color:#333}#mermaid-svg-vyCVzqqN1Tkh9fbL .label text{fill:#333}#mermaid-svg-vyCVzqqN1Tkh9fbL .node rect,#mermaid-svg-vyCVzqqN1Tkh9fbL .node circle,#mermaid-svg-vyCVzqqN1Tkh9fbL .node ellipse,#mermaid-svg-vyCVzqqN1Tkh9fbL .node polygon,#mermaid-svg-vyCVzqqN1Tkh9fbL .node path{fill:#ECECFF;stroke:#9370db;stroke-width:1px}#mermaid-svg-vyCVzqqN1Tkh9fbL .node .label{text-align:center;fill:#333}#mermaid-svg-vyCVzqqN1Tkh9fbL .node.clickable{cursor:pointer}#mermaid-svg-vyCVzqqN1Tkh9fbL .arrowheadPath{fill:#333}#mermaid-svg-vyCVzqqN1Tkh9fbL .edgePath .path{stroke:#333;stroke-width:1.5px}#mermaid-svg-vyCVzqqN1Tkh9fbL .flowchart-link{stroke:#333;fill:none}#mermaid-svg-vyCVzqqN1Tkh9fbL .edgeLabel{background-color:#e8e8e8;text-align:center}#mermaid-svg-vyCVzqqN1Tkh9fbL .edgeLabel rect{opacity:0.9}#mermaid-svg-vyCVzqqN1Tkh9fbL .edgeLabel span{color:#333}#mermaid-svg-vyCVzqqN1Tkh9fbL .cluster rect{fill:#ffffde;stroke:#aa3;stroke-width:1px}#mermaid-svg-vyCVzqqN1Tkh9fbL .cluster text{fill:#333}#mermaid-svg-vyCVzqqN1Tkh9fbL div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);font-size:12px;background:#ffffde;border:1px solid #aa3;border-radius:2px;pointer-events:none;z-index:100}#mermaid-svg-vyCVzqqN1Tkh9fbL .actor{stroke:#ccf;fill:#ECECFF}#mermaid-svg-vyCVzqqN1Tkh9fbL text.actor>tspan{fill:#000;stroke:none}#mermaid-svg-vyCVzqqN1Tkh9fbL .actor-line{stroke:grey}#mermaid-svg-vyCVzqqN1Tkh9fbL .messageLine0{stroke-width:1.5;stroke-dasharray:none;stroke:#333}#mermaid-svg-vyCVzqqN1Tkh9fbL .messageLine1{stroke-width:1.5;stroke-dasharray:2, 2;stroke:#333}#mermaid-svg-vyCVzqqN1Tkh9fbL #arrowhead path{fill:#333;stroke:#333}#mermaid-svg-vyCVzqqN1Tkh9fbL .sequenceNumber{fill:#fff}#mermaid-svg-vyCVzqqN1Tkh9fbL #sequencenumber{fill:#333}#mermaid-svg-vyCVzqqN1Tkh9fbL #crosshead path{fill:#333;stroke:#333}#mermaid-svg-vyCVzqqN1Tkh9fbL .messageText{fill:#333;stroke:#333}#mermaid-svg-vyCVzqqN1Tkh9fbL .labelBox{stroke:#ccf;fill:#ECECFF}#mermaid-svg-vyCVzqqN1Tkh9fbL .labelText,#mermaid-svg-vyCVzqqN1Tkh9fbL .labelText>tspan{fill:#000;stroke:none}#mermaid-svg-vyCVzqqN1Tkh9fbL .loopText,#mermaid-svg-vyCVzqqN1Tkh9fbL .loopText>tspan{fill:#000;stroke:none}#mermaid-svg-vyCVzqqN1Tkh9fbL .loopLine{stroke-width:2px;stroke-dasharray:2, 2;stroke:#ccf;fill:#ccf}#mermaid-svg-vyCVzqqN1Tkh9fbL .note{stroke:#aa3;fill:#fff5ad}#mermaid-svg-vyCVzqqN1Tkh9fbL .noteText,#mermaid-svg-vyCVzqqN1Tkh9fbL .noteText>tspan{fill:#000;stroke:none}#mermaid-svg-vyCVzqqN1Tkh9fbL .activation0{fill:#f4f4f4;stroke:#666}#mermaid-svg-vyCVzqqN1Tkh9fbL .activation1{fill:#f4f4f4;stroke:#666}#mermaid-svg-vyCVzqqN1Tkh9fbL .activation2{fill:#f4f4f4;stroke:#666}#mermaid-svg-vyCVzqqN1Tkh9fbL .mermaid-main-font{font-family:"trebuchet ms", verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-vyCVzqqN1Tkh9fbL .section{stroke:none;opacity:0.2}#mermaid-svg-vyCVzqqN1Tkh9fbL .section0{fill:rgba(102,102,255,0.49)}#mermaid-svg-vyCVzqqN1Tkh9fbL .section2{fill:#fff400}#mermaid-svg-vyCVzqqN1Tkh9fbL .section1,#mermaid-svg-vyCVzqqN1Tkh9fbL .section3{fill:#fff;opacity:0.2}#mermaid-svg-vyCVzqqN1Tkh9fbL .sectionTitle0{fill:#333}#mermaid-svg-vyCVzqqN1Tkh9fbL .sectionTitle1{fill:#333}#mermaid-svg-vyCVzqqN1Tkh9fbL .sectionTitle2{fill:#333}#mermaid-svg-vyCVzqqN1Tkh9fbL .sectionTitle3{fill:#333}#mermaid-svg-vyCVzqqN1Tkh9fbL .sectionTitle{text-anchor:start;font-size:11px;text-height:14px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-vyCVzqqN1Tkh9fbL .grid .tick{stroke:#d3d3d3;opacity:0.8;shape-rendering:crispEdges}#mermaid-svg-vyCVzqqN1Tkh9fbL .grid .tick text{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-vyCVzqqN1Tkh9fbL .grid path{stroke-width:0}#mermaid-svg-vyCVzqqN1Tkh9fbL .today{fill:none;stroke:red;stroke-width:2px}#mermaid-svg-vyCVzqqN1Tkh9fbL .task{stroke-width:2}#mermaid-svg-vyCVzqqN1Tkh9fbL .taskText{text-anchor:middle;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-vyCVzqqN1Tkh9fbL .taskText:not([font-size]){font-size:11px}#mermaid-svg-vyCVzqqN1Tkh9fbL .taskTextOutsideRight{fill:#000;text-anchor:start;font-size:11px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-vyCVzqqN1Tkh9fbL .taskTextOutsideLeft{fill:#000;text-anchor:end;font-size:11px}#mermaid-svg-vyCVzqqN1Tkh9fbL .task.clickable{cursor:pointer}#mermaid-svg-vyCVzqqN1Tkh9fbL .taskText.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-vyCVzqqN1Tkh9fbL .taskTextOutsideLeft.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-vyCVzqqN1Tkh9fbL .taskTextOutsideRight.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-vyCVzqqN1Tkh9fbL .taskText0,#mermaid-svg-vyCVzqqN1Tkh9fbL .taskText1,#mermaid-svg-vyCVzqqN1Tkh9fbL .taskText2,#mermaid-svg-vyCVzqqN1Tkh9fbL .taskText3{fill:#fff}#mermaid-svg-vyCVzqqN1Tkh9fbL .task0,#mermaid-svg-vyCVzqqN1Tkh9fbL .task1,#mermaid-svg-vyCVzqqN1Tkh9fbL .task2,#mermaid-svg-vyCVzqqN1Tkh9fbL .task3{fill:#8a90dd;stroke:#534fbc}#mermaid-svg-vyCVzqqN1Tkh9fbL .taskTextOutside0,#mermaid-svg-vyCVzqqN1Tkh9fbL .taskTextOutside2{fill:#000}#mermaid-svg-vyCVzqqN1Tkh9fbL .taskTextOutside1,#mermaid-svg-vyCVzqqN1Tkh9fbL .taskTextOutside3{fill:#000}#mermaid-svg-vyCVzqqN1Tkh9fbL .active0,#mermaid-svg-vyCVzqqN1Tkh9fbL .active1,#mermaid-svg-vyCVzqqN1Tkh9fbL .active2,#mermaid-svg-vyCVzqqN1Tkh9fbL .active3{fill:#bfc7ff;stroke:#534fbc}#mermaid-svg-vyCVzqqN1Tkh9fbL .activeText0,#mermaid-svg-vyCVzqqN1Tkh9fbL .activeText1,#mermaid-svg-vyCVzqqN1Tkh9fbL .activeText2,#mermaid-svg-vyCVzqqN1Tkh9fbL .activeText3{fill:#000 !important}#mermaid-svg-vyCVzqqN1Tkh9fbL .done0,#mermaid-svg-vyCVzqqN1Tkh9fbL .done1,#mermaid-svg-vyCVzqqN1Tkh9fbL .done2,#mermaid-svg-vyCVzqqN1Tkh9fbL .done3{stroke:grey;fill:#d3d3d3;stroke-width:2}#mermaid-svg-vyCVzqqN1Tkh9fbL .doneText0,#mermaid-svg-vyCVzqqN1Tkh9fbL .doneText1,#mermaid-svg-vyCVzqqN1Tkh9fbL .doneText2,#mermaid-svg-vyCVzqqN1Tkh9fbL .doneText3{fill:#000 !important}#mermaid-svg-vyCVzqqN1Tkh9fbL .crit0,#mermaid-svg-vyCVzqqN1Tkh9fbL .crit1,#mermaid-svg-vyCVzqqN1Tkh9fbL .crit2,#mermaid-svg-vyCVzqqN1Tkh9fbL .crit3{stroke:#f88;fill:red;stroke-width:2}#mermaid-svg-vyCVzqqN1Tkh9fbL .activeCrit0,#mermaid-svg-vyCVzqqN1Tkh9fbL .activeCrit1,#mermaid-svg-vyCVzqqN1Tkh9fbL .activeCrit2,#mermaid-svg-vyCVzqqN1Tkh9fbL .activeCrit3{stroke:#f88;fill:#bfc7ff;stroke-width:2}#mermaid-svg-vyCVzqqN1Tkh9fbL .doneCrit0,#mermaid-svg-vyCVzqqN1Tkh9fbL .doneCrit1,#mermaid-svg-vyCVzqqN1Tkh9fbL .doneCrit2,#mermaid-svg-vyCVzqqN1Tkh9fbL .doneCrit3{stroke:#f88;fill:#d3d3d3;stroke-width:2;cursor:pointer;shape-rendering:crispEdges}#mermaid-svg-vyCVzqqN1Tkh9fbL .milestone{transform:rotate(45deg) scale(0.8, 0.8)}#mermaid-svg-vyCVzqqN1Tkh9fbL .milestoneText{font-style:italic}#mermaid-svg-vyCVzqqN1Tkh9fbL .doneCritText0,#mermaid-svg-vyCVzqqN1Tkh9fbL .doneCritText1,#mermaid-svg-vyCVzqqN1Tkh9fbL .doneCritText2,#mermaid-svg-vyCVzqqN1Tkh9fbL .doneCritText3{fill:#000 !important}#mermaid-svg-vyCVzqqN1Tkh9fbL .activeCritText0,#mermaid-svg-vyCVzqqN1Tkh9fbL .activeCritText1,#mermaid-svg-vyCVzqqN1Tkh9fbL .activeCritText2,#mermaid-svg-vyCVzqqN1Tkh9fbL .activeCritText3{fill:#000 !important}#mermaid-svg-vyCVzqqN1Tkh9fbL .titleText{text-anchor:middle;font-size:18px;fill:#000;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-vyCVzqqN1Tkh9fbL g.classGroup text{fill:#9370db;stroke:none;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);font-size:10px}#mermaid-svg-vyCVzqqN1Tkh9fbL g.classGroup text .title{font-weight:bolder}#mermaid-svg-vyCVzqqN1Tkh9fbL g.clickable{cursor:pointer}#mermaid-svg-vyCVzqqN1Tkh9fbL g.classGroup rect{fill:#ECECFF;stroke:#9370db}#mermaid-svg-vyCVzqqN1Tkh9fbL g.classGroup line{stroke:#9370db;stroke-width:1}#mermaid-svg-vyCVzqqN1Tkh9fbL .classLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.5}#mermaid-svg-vyCVzqqN1Tkh9fbL .classLabel .label{fill:#9370db;font-size:10px}#mermaid-svg-vyCVzqqN1Tkh9fbL .relation{stroke:#9370db;stroke-width:1;fill:none}#mermaid-svg-vyCVzqqN1Tkh9fbL .dashed-line{stroke-dasharray:3}#mermaid-svg-vyCVzqqN1Tkh9fbL #compositionStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-vyCVzqqN1Tkh9fbL #compositionEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-vyCVzqqN1Tkh9fbL #aggregationStart{fill:#ECECFF;stroke:#9370db;stroke-width:1}#mermaid-svg-vyCVzqqN1Tkh9fbL #aggregationEnd{fill:#ECECFF;stroke:#9370db;stroke-width:1}#mermaid-svg-vyCVzqqN1Tkh9fbL #dependencyStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-vyCVzqqN1Tkh9fbL #dependencyEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-vyCVzqqN1Tkh9fbL #extensionStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-vyCVzqqN1Tkh9fbL #extensionEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-vyCVzqqN1Tkh9fbL .commit-id,#mermaid-svg-vyCVzqqN1Tkh9fbL .commit-msg,#mermaid-svg-vyCVzqqN1Tkh9fbL .branch-label{fill:lightgrey;color:lightgrey;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-vyCVzqqN1Tkh9fbL .pieTitleText{text-anchor:middle;font-size:25px;fill:#000;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-vyCVzqqN1Tkh9fbL .slice{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-vyCVzqqN1Tkh9fbL g.stateGroup text{fill:#9370db;stroke:none;font-size:10px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-vyCVzqqN1Tkh9fbL g.stateGroup text{fill:#9370db;fill:#333;stroke:none;font-size:10px}#mermaid-svg-vyCVzqqN1Tkh9fbL g.statediagram-cluster .cluster-label text{fill:#333}#mermaid-svg-vyCVzqqN1Tkh9fbL g.stateGroup .state-title{font-weight:bolder;fill:#000}#mermaid-svg-vyCVzqqN1Tkh9fbL g.stateGroup rect{fill:#ECECFF;stroke:#9370db}#mermaid-svg-vyCVzqqN1Tkh9fbL g.stateGroup line{stroke:#9370db;stroke-width:1}#mermaid-svg-vyCVzqqN1Tkh9fbL .transition{stroke:#9370db;stroke-width:1;fill:none}#mermaid-svg-vyCVzqqN1Tkh9fbL .stateGroup .composit{fill:white;border-bottom:1px}#mermaid-svg-vyCVzqqN1Tkh9fbL .stateGroup .alt-composit{fill:#e0e0e0;border-bottom:1px}#mermaid-svg-vyCVzqqN1Tkh9fbL .state-note{stroke:#aa3;fill:#fff5ad}#mermaid-svg-vyCVzqqN1Tkh9fbL .state-note text{fill:black;stroke:none;font-size:10px}#mermaid-svg-vyCVzqqN1Tkh9fbL .stateLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.7}#mermaid-svg-vyCVzqqN1Tkh9fbL .edgeLabel text{fill:#333}#mermaid-svg-vyCVzqqN1Tkh9fbL .stateLabel text{fill:#000;font-size:10px;font-weight:bold;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-vyCVzqqN1Tkh9fbL .node circle.state-start{fill:black;stroke:black}#mermaid-svg-vyCVzqqN1Tkh9fbL .node circle.state-end{fill:black;stroke:white;stroke-width:1.5}#mermaid-svg-vyCVzqqN1Tkh9fbL #statediagram-barbEnd{fill:#9370db}#mermaid-svg-vyCVzqqN1Tkh9fbL .statediagram-cluster rect{fill:#ECECFF;stroke:#9370db;stroke-width:1px}#mermaid-svg-vyCVzqqN1Tkh9fbL .statediagram-cluster rect.outer{rx:5px;ry:5px}#mermaid-svg-vyCVzqqN1Tkh9fbL .statediagram-state .divider{stroke:#9370db}#mermaid-svg-vyCVzqqN1Tkh9fbL .statediagram-state .title-state{rx:5px;ry:5px}#mermaid-svg-vyCVzqqN1Tkh9fbL .statediagram-cluster.statediagram-cluster .inner{fill:white}#mermaid-svg-vyCVzqqN1Tkh9fbL .statediagram-cluster.statediagram-cluster-alt .inner{fill:#e0e0e0}#mermaid-svg-vyCVzqqN1Tkh9fbL .statediagram-cluster .inner{rx:0;ry:0}#mermaid-svg-vyCVzqqN1Tkh9fbL .statediagram-state rect.basic{rx:5px;ry:5px}#mermaid-svg-vyCVzqqN1Tkh9fbL .statediagram-state rect.divider{stroke-dasharray:10,10;fill:#efefef}#mermaid-svg-vyCVzqqN1Tkh9fbL .note-edge{stroke-dasharray:5}#mermaid-svg-vyCVzqqN1Tkh9fbL .statediagram-note rect{fill:#fff5ad;stroke:#aa3;stroke-width:1px;rx:0;ry:0}:root{--mermaid-font-family: '"trebuchet ms", verdana, arial';--mermaid-font-family: "Comic Sans MS", "Comic Sans", cursive}#mermaid-svg-vyCVzqqN1Tkh9fbL .error-icon{fill:#522}#mermaid-svg-vyCVzqqN1Tkh9fbL .error-text{fill:#522;stroke:#522}#mermaid-svg-vyCVzqqN1Tkh9fbL .edge-thickness-normal{stroke-width:2px}#mermaid-svg-vyCVzqqN1Tkh9fbL .edge-thickness-thick{stroke-width:3.5px}#mermaid-svg-vyCVzqqN1Tkh9fbL .edge-pattern-solid{stroke-dasharray:0}#mermaid-svg-vyCVzqqN1Tkh9fbL .edge-pattern-dashed{stroke-dasharray:3}#mermaid-svg-vyCVzqqN1Tkh9fbL .edge-pattern-dotted{stroke-dasharray:2}#mermaid-svg-vyCVzqqN1Tkh9fbL .marker{fill:#333}#mermaid-svg-vyCVzqqN1Tkh9fbL .marker.cross{stroke:#333} :root { --mermaid-font-family: "trebuchet ms", verdana, arial;} #mermaid-svg-vyCVzqqN1Tkh9fbL { color: rgba(0, 0, 0, 0.75); font: ; }

调用

提交审查结果

保存审查结果

Jenkins

SonarQube Scanner

SonarQube

MySql

??安装完插件之后需要添加一个SonarQube的凭证,如下图:

Jenkins系列之六整合SonarQube,深度剖析原理_面试

Jenkins系列之六整合SonarQube,深度剖析原理_面试_02

二、配置

??配置SonarQube服务地址,并关闭SonarQube的审查结果上传到SCM功能。

Jenkins系列之六整合SonarQube,深度剖析原理_Java_03Jenkins系列之六整合SonarQube,深度剖析原理_Java_04Jenkins系列之六整合SonarQube,深度剖析原理_面试_05

三、创建项目验证

??以之前创建的Maven项目为例,添加构建步骤,并加入Sonar执行配置参数。

Jenkins系列之六整合SonarQube,深度剖析原理_ide_06Jenkins系列之六整合SonarQube,深度剖析原理_ide_07

配置文件具体内容如下:


# must be unique in a given SonarQube instance 

sonar.projectKey=iot-service

# this is the name and version displayed in the SonarQube UI. Was mandatory prior to SonarQube 6.1. 

sonar.projectName=iot-service

sonar.projectVersion=1.0

# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows. 

# This property is optional if sonar.modules is set. 

sonar.sources=. 

sonar.exclusions=**/test/**,**/target/** 

sonar.java.source=1.8 

sonar.java.target=1.8 


# 总结

蚂蚁面试比较重视基础,所以Java那些基本功一定要扎实。蚂蚁的工作环境还是挺赞的,因为我面的是稳定性保障部门,还有许多单独的小组,什么三年1班,很有青春的感觉。面试官基本水平都比较高,基本都P7以上,除了基础还问了不少架构设计方面的问题,收获还是挺大的。

**[资料领取方式:戳这里](https://gitee.com/vip204888/java-p7)**

* * *

**经历这次面试我还通过一些渠道发现了需要大厂真实面试主要有**:蚂蚁金服、拼多多、阿里云、百度、唯品会、携程、丰巢科技、乐信、软通动力、OPPO、银盛支付、中国平安等初,中级,高级Java面试题集合,附带超详细答案,希望能帮助到大家。

![蚂蚁金服5面,总结了49个面试题,遇到的面试官都是P7级别以上](https://upload-images.jianshu.io/upload_images/24616006-2b976d3b5a750638?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)