jenkins - 确认 SonarQube 结果适用于主分支
问题描述
因为不知道Sonar是不是在做奇怪的事情,我只是想确认一下它确实是在扫描master分支而不是feature分支。
我团队中的人说 SonarCube 对功能分支进行了测试。据我所知,它在主分支上运行了测试。我们正在使用 Sonar 7.9.1,我的意图是针对功能分支运行。
詹金斯文件片段:
stage('Send sonarqube reports') {
sh """
sonar-scanner -Dsonar.host.url=${SONAR_CIRRUS} -Dsonar.java.libraries=/home/bcjenkins/.m2/repository/org/projectlombok/lombok/1.18.8/lombok-1.18.8.jar
"""
JSON_STRING_SONAR_METRICS = sh (
script: "curl -X GET -H \'Content-Type: application/json\' -H \'Accept: application/octet-stream\' \'${SONAR_CIRRUS}/api/qualitygates/project_status?projectKey=cirrus-bluecost-ssc-file-generator\'",
returnStdout: true
).trim()
println "The JSON_STRING_SONAR_METRICS=${JSON_STRING_SONAR_METRICS}";
def sonarQube_Results = readJSON text: "${JSON_STRING_SONAR_METRICS}";
def CodeCoverageEntryThreshold = sonarQube_Results.projectStatus.status;
if(CodeCoverageEntryThreshold == "ERROR"){
error("[cirrus-bluecost-ssc-file-generator] Code qualitygates did not PASSED. Please check the results in our Sonarqube server.\n" +
"\tTo view the sonarqube results-> ${SONAR_CIRRUS}/dashboard?id=cirrus-bluecost-ssc-file-generator\n")
}
else if(CodeCoverageEntryThreshold == "FAILED"){
error("[cirrus-bluecost-ssc-file-generator] Code qualitygates did not PASSED. Please check the results in our Sonarqube server.\n" +
"\tTo view the sonarqube results-> ${SONAR_CIRRUS}/dashboard?id=cirrus-bluecost-ssc-file-generator\n")
}
else {
CodeCoverage_resultMsg = "[cirrus-bluecost-ssc-file-generator] Code qualitygates PASSED. Please check the results in our Sonarqube server.\n" +
"\tTo view the sonarqube results-> ${SONAR_CIRRUS}/dashboard?id=cirrus-bluecost-ssc-file-generator\n";
slackSend channel: "${SONAR_SLACK_CHANNEL}", color: 'good', failOnError: false, message: "${CodeCoverage_resultMsg}", teamDomain: 'ibm-ic2e-sprint', tokenCredentialId: SLACK_DOMAIN_CREDENTIALS
}
}
解决方案
关于https://docs.sonarqube.org/latest/branches/overview/
主/主分支
这是默认分支,通常对应于为下一个版本开发的内容。此分支通常在开发团队中称为“主”或“头”,并在未提供特定分支参数时进行分析。SonarQube 将此分支标记为 Main Branch,并且在 Community Edition 中,这是您可以分析的唯一分支 。
如果我们使用SonarQube 社区版,我们只能分析main
ormater
分支。
如果我们需要分析其他分支,我们应该至少使用SonarQube 开发版,如下所述:-
分支分析
从Developer Edition开始提供分支分析。
编辑1:
SonarQube提供SonarLint ( https://www.sonarlint.org/ )作为 IDE 扩展,包括Eclipse、IntelliJ IDEA等。
我们能够将我们的 IDE 配置为连接到内部SonarQube服务器,并使用此插件在开发人员机器上执行本地分析,然后将它们合并到主分支或主分支。
编辑2:
使用Eclipse配置SonarLint的示例位于https://github.com/SonarSource/sonarlint-eclipse/wiki/Connected-Mode
推荐阅读
- php - 将 MySQLi 开放语句换成预准备语句
- spring-boot - 如何使用 tornadoFx 将多部分文件发送到 springboot 服务器?
- typescript - TypeScript Compiler API - 访问编译器阶段的输出
- .net - PSCredential 不包含名为“GetNetworkCredential”的方法
- php - 不能在扩展控制器上使用 laravel 响应
- r - 如果至少存在一个元素,如何提供结果?
- javascript - 如何重新声明具有相同名称但使用 Typescript 中的代码的方法
- unix - 如何从某年删除基于某种模式的文件
- c# - 这是等价的吗?(int) listofobj?.Count() 到 (listofobj == null)?0:listofobj.Count();
- angularjs - 如何在 javascript 中导入在 html 中引用的这个库?