1、下载Sonarqube

  • https://www.sonarqube.org/downloads/
    -Centos下Jenkins全流程环境搭建和配置-5-Sonarqube代码质量审查

2、Centos下解压

3、adduser sonar

4、chown –R sonar:sonar 解压的文件夹

5、修改配置文件: sonarqube-7.7/conf/sonar.properties

新增:
sonar.jdbc.username=signalway
sonar.jdbc.password=1234zxcv
sonar.jdbc.url=jdbc:mysql://172.18.2.3:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance

sonar.web.host=0.0.0.0
sonar.web.context=/
sonar.web.port=8081

6、修改内存:

su root
sysctl -w vm.max_map_count=262144
查看结果:
sysctl -a|grep vm.max_map_count

显示:
vm.max_map_count = 262144
上述方法修改之后,如果重启虚拟机将失效,所以:
解决办法:
在 /etc/sysctl.conf文件最后添加一行
vm.max_map_count=262144
即可永久修改

7、如要汉化的话

  • 汉化包下载:https://github.com/SonarQubeCommunity/sonar-l10n-zh
  • 导入汉化包,拷贝到:/opt/weijlshell/sonarqube-7.7/extensions/plugins

8、搞定,启动

  • su sonar
  • cd /opt/weijlshell/sonarqube-7.7/bin/linux-x86-64
  • ./sonar.sh start
  • 如果有报错,权限问题,那就再重新解压,再搞一遍(也不知道是抽什么风,有时候第一遍解压给权限就是不行…)

9、安装jenkins插件

Centos下Jenkins全流程环境搭建和配置-5-Sonarqube代码质量审查
也就是http://updates.jenkins-ci.org/download/plugins/这里面的sonar

进入jenkins-系统配置进行配置调度

Centos下Jenkins全流程环境搭建和配置-5-Sonarqube代码质量审查
名字随意,写上对应的ip和端口,token来自:

Centos下Jenkins全流程环境搭建和配置-5-Sonarqube代码质量审查
随便写个名字
Centos下Jenkins全流程环境搭建和配置-5-Sonarqube代码质量审查
到此,配对成功~

10、Jenkins任务的配置

一个自由项目
拉git代码
Centos下Jenkins全流程环境搭建和配置-5-Sonarqube代码质量审查
构建时进行代码评审
Centos下Jenkins全流程环境搭建和配置-5-Sonarqube代码质量审查

  • 关键的Analysis properties这样写:
    sonar.projectKey=parking2xtestSonar//随便写
    sonar.projectName=parking2xtestSonar//随便写
    sonar.projectVersion=1.0//就1.0可以了
    sonar.language=java//语言类型
    sonar.java.binaries=$WORKSPACE//class路径,但是这样写也行,会自动寻址,这里会读到jenkins工作目录
    sonar.sources=$WORKSPACE//src路径,但是这样写也行,会自动寻址

  • 无注释的如下(便于复制):
    sonar.projectKey=parking2xtestSonar
    sonar.projectName=parking2xtestSonar
    sonar.projectVersion=1.0
    sonar.language=java
    sonar.java.binaries=WORKSPACEsonar.sources=WORKSPACE sonar.sources=WORKSPACE

11、 最后,跑起来,定时、挂勾子触发都可以,然后直接访问sonar的url就行了

  • Sonar默认帐号密码都是admin

相关文章:

  • 2021-12-11
  • 2022-12-23
  • 2021-08-17
  • 2021-04-21
  • 2021-12-12
  • 2022-03-06
  • 2021-10-14
  • 2022-12-23
猜你喜欢
  • 2021-07-23
  • 2021-07-19
  • 2021-06-18
  • 2021-10-06
  • 2021-10-27
  • 2021-05-26
  • 2021-07-16
相关资源
相似解决方案