Jenkins+SonarQube代码审查
SonarQube简介
SonarQube是一个用于管理代码质量的开放平台,可以快速的定位代码中潜在的或者明显的错误。
目前支持java,C#,C/C++,Python,PL/SQL,Cobol,JavaScrip,Groovy等二十几种编程语言的代码质量管理与检 测,底层使用elasticsearch作为代码检索工具。
官网:https://www.sonarqube.org/
实验环境要求:
软件 | 服务器 | 版本 |
---|---|---|
JDK | 持续集成服务器 | 1.8 |
MySQL | 持续集成服务器 | 5.7 |
SonarQube | 持续集成服务器 | 6.7.4 |
SonarQube的配置
安装MySQL
略
下载sonar压缩包:
https://www.sonarqube.org/downloads/
解压sonar,并设置权限
点击查看代码
yum install unzip
unzip sonarqube-6.7.4.zip
mkdir /opt/sonar
mv sonarqube-6.7.4/* /opt/sonar
useradd sonar #创建sonar用户,必须sonar用于启动,否则报错
chown -R sonar. /opt/sonar #更改sonar目录及文件权限
修改sonar配置文件
vi /opt/sonarqube-6.7.4/conf/sonar.properties
内容如下:
注意:sonar默认监听9000端口,如果9000端口被占用,需要更改。
切换为sonar用户,启动sonar
点击查看代码
cd /opt/sonar
su sonar ./bin/linux-x86-64/sonar.sh start #启动
su sonar ./bin/linux-x86-64/sonar.sh status #查看状态
su sonar ./bin/linux-x86-64/sonar.sh stop #停止
tail -f logs/sonar.logs #查看日志
访问sonar
创建token
可以在初始界面创建第一个token
如果忘记了你设置的token,可以点击头像进入管理员账户重新生成一个token
实现代码审查
安装SonarQube Scanner插件
略
Jenkins安装SonarQube
添加SonarQube凭证
Jenkins配置SonarQube
在项目添加SonarQube代码审查
点击查看代码
# must be unique in a given SonarQube instance
sonar.projectKey=web_demo_freestyle
# this is the name and version displayed in the SonarQube UI. Was mandatory prior to SonarQube 6.1.
sonar.projectName=web_demo_freestyle
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
# Encoding of the source code. Default is default system encoding
sonar.sourceEncoding=UTF-8
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· AI与.NET技术实操系列(六):基于图像分类模型对图像进行分类