DEVOPS technical practices _11: Jenkins Integrated Sonar

Foreword

There has already been introduced sonar installation, simple application, use the following simple jenkins integrated sonar and look at the short answer is, for the installation of sonar does not describe

A brief introduction of a sonar

Continually checks to avoid low quality code, such as SonarQube tools to help us do so. After each code is submitted, it will perform code analysis on the code.

Analysis code analysis tools are some of the rules defined based on, if the code by the error threshold, then it will allow the life cycle to the next step, if more than the set threshold, then the direct return an error.

SonarQube is code quality management tool that allows teams to manage, track and improve their quality of source code, it contains rules, a WEB-based applications and alarm threshold. It contains seven types of code quality parameters, and design configurations are added, repeating, unit testing, complexity, potential bug, coding rules and comments.

SoanrQube is an open source tool that supports almost all popular languages, and CI tools and can be integrated effectively perform continuous checks.

Now some tools

Jenkins:192.168.132.131

Gitlab: 192,168,132,132

Sonar:192.168.132.133

Artifactory:192.168.132.134

Two configuration sonar

2.1 generation token

Generating a token, the token is connected to the key sonar and Jenkins

Generated token

token:278c0c5ddadca63754f0fa9ce50ba99c20214fb5

 

2.2  Creating a project in the SonarQube

(1) Click Administrator | Projects (tab) | Management

(2) Click the Create Project button and fill out the information below.

 

 Once created should display the following information.

 

2.3  for SonarQube build breaker plug-in installation

该插件允许CI system(Jenkins)在质量门的条件不能够满足的情况下,强制Jenkins构建失败。安装插件,执行以下步骤。

安装插件之前,先去查看一下兼容性列表,可以查看以下网址。兼容性列表

下载构建代理插件,下载地址

切换到/tmp目录和下载构建代理插件,使用以下命令。

[root@node3 ~]# cd /tmp/

[root@node3 tmp]# wget https://github.com/jbocc/sonar-build-breaker/releases/download/2.2/sonar-build-breaker-plugin-2.2.jar

移动.jar文件到/home/sonar/sonarqube/extensions/plugins/目录下

cp sonar-build-breaker-plugin-2.2.jar   /home/sonar/sonarqube/extensions/plugins/

[sonar@node3 ~]$ ./sonarqube/bin/linux-x86-64/sonar.sh restart

重新启动完成后,应该看到界面有Build Breaker选项了。

2.3 创建质量门

针对想要breaker plugin起作用,去工作,那么需要创建quality gate, quality gate只是一些条件。当jenkins运行的时候,它执行quality profiles和quality gate. 假如quality gate检查通过,那么Jenkins pipeline继续,假如检查失败的话,那么Jenkins pipeline将会终止,但分析会存在的。

2.3.1 点击Quality Gates

2.3.2 点击添加条件

2.3.4添加条件信息如下

 

配置建的项目使用创建的质量门。

 

三 jenkins集成sonar

3.1 在jenkins中安装sonar插件

在Jenkins中配置SonarQube

3.2 在管理jenkins的系统设置配置

需要自己添加凭据

暂时配置完成

Guess you like

Origin www.cnblogs.com/zyxnhr/p/11781402.html