sakurayz 2019-10-24
SonarQube代码质检:1.提交代码-->gitlab-->jenkins抓取-->sonarqube质量检测-->maven编译-->shell-->web集群-->重载服务
SonarQube服务安装
[ ~]# yum install java -y
[ ~]# yum localinstall mysql-community-*.rpm -y
[ ~]# systemctl start mysqld
[ ~]# mysql
mysql> create database sonar charset utf8;
[ ~]# unzip sonarqube-7.0.zip -d /usr/local/
[ ~]# ln -s /usr/local/sonarqube-7.0/ /usr/local/sonarqube
#配置sonar连接mysql数据库
[ ~]# vim /usr/local/sonarqube/conf/sonar.properties
#启动sonar
[ ~]# useradd sonar
[ ~]# chown -R sonar.sonar /usr/local/sonarqube
[ ~]# chown -R sonar.sonar /usr/local/sonarqube-7.0/
[ ~]# su - sonar -c "/usr/local/sonarqube/bin/linux-x86-64/sonar.sh start"
默认访问的url http://IP:9000
用户:admin
密码:admin
jenkins: b90b5d70562485f00caeb326a63d496af7aeaf3f 这号码可以生成
导入插件
[ ~]# tar xf sonar_plugins.tar.gz
[ ~]# rm -f /usr/local/sonarqube/extensions/plugins/*
[ ~]# cp -rp plugins/* /usr/local/sonarqube/extensions/plugins/
重载服务
[ ~]# su - sonar -c "/usr/local/sonarqube/bin/linux-x86-64/sonar.sh restart"
如何检测代码:
1.安装sonar-scanner 客户端---> 谁要实现推送代码质检,就在谁上面安装
[ ~]# unzip sonar-scanner-cli-4.0.0.1744-linux.zip -d /usr/local/
[ ~]# ln -s /usr/local/sonar-scanner-4.0.0.1744-linux/ /usr/local/sonar-scanner
2.配置sonar-scanner
[ ~]# vim /usr/local/sonar-scanner/conf/sonar-scanner.properties
sonar.host.url=http://sonar.oldxu.com:9000
sonar.login=b90b5d70562485f00caeb326a63d496af7aeaf3f
sonar.sourceEncoding=UTF-8
3.配置hosts解析
[ ~]# cat /etc/hosts
10.0.0.110 gitlab.oldxx.com
10.0.0.130 sonar.oldxx.com
4.进入代码目录执行客户端检测命令
/usr/local/sonar-scanner/bin/sonar-scanner \
-Dsonar.projectKey=php \
-Dsonar.sources=.
mvn sonar:sonar \
-Dsonar.host.url=http://sonar.oldxx.com:9000 \
-Dsonar.login=65e35ff20a89bf3d05b94b1c693b326290337b6c