sonarqube的多分支检查

发布时间:2024年01月18日

sonarqube的多分支检查

参考文档:

Sonarqube(社区版)支持扫描多分支配置
SonarQute安装与多分支扫描分析插件安装
持续集成交付CICD:Sonarqube多分支代码扫描

1.手动安装插件

插件地址 : https://github.com/mc1arke/sonarqube-community-branch-plugin
需要注意的是,不同的SonarQube版本使用的插件版本也不一样,在上面我们安装的SonarQube为9.9.x,所以下载的插件版本应该是1.14.0
在这里插入图片描述

1.下载插件到/opt/sonarqube/extensions/plugins/

? ~/Downloads/ wget https://github.com/mc1arke/sonarqube-community-branch-plugin/releases/download/1.14.0/sonarqube-community-branch-plugin-1.14.0.jar
? ~/data/sonar/sonarqube/extensions/plugins/ cp ~/Downloads/sonarqube-community-branch-plugin-1.14.0.jar ./
? ~/data/sonar/sonarqube/extensions/plugins/ ll
total 24944
-rw-r--r--@ 1 admin  staff    69K  1 17 15:22 sonar-l10n-zh-plugin-9.9.jar
-rw-r--r--@ 1 admin  staff    12M  1 18 14:09 sonarqube-community-branch-plugin-1.14.0.jar
? ~/data/sonar/sonarqube/extensions/plugins/ 
? ~/data/sonar/sonarqube/extensions/plugins/ 

2.配置sonarqube配置文件:/opt/sonarqube/conf/sonar.properties 添加以下内容:

sonar.web.javaAdditionalOpts=-javaagent:./extensions/plugins/sonarqube-community-branch-plugin-1.14.0.jar=web
sonar.ce.javaAdditionalOpts=-javaagent:./extensions/plugins/sonarqube-community-branch-plugin-1.14.0.jar=ce
? ~/data/sonar/sonarqube/data/ docker exec -u root -it  3f7b95a39582 bash
root@3f7b95a39582:/opt/sonarqube# 
root@3f7b95a39582:/opt/sonarqube# id
uid=0(root) gid=0(root) groups=0(root)
root@3f7b95a39582:/opt/sonarqube# cd conf/
root@3f7b95a39582:/opt/sonarqube/conf# ls -lth
total 24K
-r-xr-xr-x 1 root root 21K Nov 10 16:24 sonar.properties
root@3f7b95a39582:/opt/sonarqube/conf# 
root@3f7b95a39582:/opt/sonarqube/conf# chmod 755 sonar.properties 
root@3f7b95a39582:/opt/sonarqube/conf# ls -thl
total 24K
-rwxr-xr-x 1 root root 21K Nov 10 16:24 sonar.properties
root@3f7b95a39582:/opt/sonarqube/conf# echo "sonar.web.javaAdditionalOpts=-javaagent:./extensions/plugins/sonarqube-community-branch-plugin-1.14.0.jar=web" >> sonar.properties 
root@3f7b95a39582:/opt/sonarqube/conf# 
root@3f7b95a39582:/opt/sonarqube/conf# echo "sonar.ce.javaAdditionalOpts=-javaagent:./extensions/plugins/sonarqube-community-branch-plugin-1.14.0.jar=ce" >> sonar.properties
root@3f7b95a39582:/opt/sonarqube/conf# 
root@3f7b95a39582:/opt/sonarqube/conf# cat sonar.properties 
....
# Telemetry - Share anonymous SonarQube statistics
# By sharing anonymous SonarQube statistics, you help us understand how SonarQube is used so we can improve the product to work even better for you.
# We don't collect source code or IP addresses. And we don't share the data with anyone else.
#sonar.telemetry.enable=true
sonar.web.javaAdditionalOpts=-javaagent:./extensions/plugins/sonarqube-community-branch-plugin-1.14.0.jar=web
sonar.ce.javaAdditionalOpts=-javaagent:./extensions/plugins/sonarqube-community-branch-plugin-1.14.0.jar=ce
root@3f7b95a39582:/opt/sonarqube/conf# 

3. 重启容器

? ~/data/sonar/sonarqube/data/ docker ps 
CONTAINER ID   IMAGE           COMMAND                   CREATED        STATUS       PORTS                    NAMES
3f7b95a39582   sonarqube:lts   "/opt/sonarqube/dock…"   28 hours ago   Up 3 hours   0.0.0.0:9000->9000/tcp   sonarqube
bf16eb3ff46c   postgres:11.4   "docker-entrypoint.s…"   28 hours ago   Up 3 hours   0.0.0.0:5432->5432/tcp   db
e35046cc2cf3   redis           "docker-entrypoint.s…"   6 months ago   Up 3 hours   0.0.0.0:6379->6379/tcp   redis
? ~/data/sonar/sonarqube/data/ 
? ~/data/sonar/sonarqube/data/ 
? ~/data/sonar/sonarqube/data/ docker restart 3f7b95a39582
3f7b95a39582
? ~/data/sonar/sonarqube/data/ 

4. 扫描分支sonar.branch.name

? ~/work/test/ [test_release_20231213] mvn clean  verify org.sonarsource.scanner.maven:sonar-maven-plugin:3.6.0.1398:sonar \
-Dsonar.projectKey=test \
-Dsonar.host.url=http://localhost:9000 \
-Dsonar.login=sqp_d065f574824439dd24fc05bed6c99b66269d56fa \
-Dsonar.branch.name=test_release_20231213

在这里插入图片描述

2. docker安装

从插件的github看到他们直接把sonarqube和branch-plugin搞到了一个镜像里面。。。早知道就不单独弄sonarqube了,这个多方便。。。。
在这里插入图片描述

文章来源:https://blog.csdn.net/xiaolixi199311/article/details/135672626
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。