简体   繁体   English

Sonar Gerrit插件未报告结果

[英]Sonar Gerrit plugin not reporting results

We utilize the pipeline and after the build completes successfully we are running the following: 我们利用管道,并在构建成功完成后运行以下命令:

bat "mvn sonar:sonar -B -s ${buildSettings} -Dsonar.analysis.mode=preview -Dsonar.skipDesign=true -Dsonar.report.export.path=sonar-report.json"

sonarToGerrit(severity: 'Major', postScore: true, category: 'Code-Review', newIssuesOnly: true, issuesScore: '0', noIssuesScore: '0', changedLinesOnly: true)

The below build log shows that it found a good number of issues but yet the issues to be commented is 0. 下面的构建日志显示它发现了很多问题,但是要评论的问题是0。

Build log 构建日志

Other posts suggest that it may not be finding the report but I don't believe it's the case as it found a number of issues. 其他帖子表明它可能找不到报告,但我认为情况并非如此,因为它发现了许多问题。 Any pipeline configuration advice would be much appreciated. 任何管道配置建议将不胜感激。

We are using Sonar Gerrit plugin version 2.2.1, Gerrit Trigger 2.27.3 and Jenkins Enterprise version is 2.60.3.1. 我们正在使用Sonar Gerrit插件版本2.2.1,Gerrit触发器2.27.3和Jenkins Enterprise版本是2.60.3.1。

The most common case regarding to your question is related to the fact that SonarQube checks the whole project, regardless of amount of changes that were done in particular change. 与您的问题有关的最常见情况与SonarQube会检查整个项目有关,而与所做的更改量无关,无论是特定的更改。 When creating a new report, it compares a result with a result that is stored to it's database (with previously found issues that were found in a mode other than preview). 创建新报告时,它会将结果与存储在数据库中的结果进行比较(与以前发现的问题相比,这些问题是在非预览模式下发现的)。 Thus sonar marks as new all the issues that it was not aware about before (and if you don't store this information in SonarQube at all - all the issues will be marked as new). 因此,声纳将以前未意识到的所有问题标记为新问题(并且如果您根本不将这些信息存储在SonarQube中,则所有问题都将被标记为新问题)。 But sonar-gerrit plugin can only post issues to the files that were affected by the change it is verifying. 但是sonar-gerrit插件只能将问题发布到受其验证更改影响的文件中。 So, even if you set to "false" the settings "newIssuesOnly" and "changedLinesOnly", all the issues in files not affected by the change will be ignored. 因此,即使将“ newIssuesOnly”和“ changedLinesOnly”设置设为“ false”,文件中不受更改影响的所有问题也将被忽略。

Shortly, check that the issues marked with "isNew"="true" in your sonar report were actually changed (for changedLinesOnly=true) or located in the changed files (for changedLinesOnly = false) in the commit you are trying to check. 不久,请检查声纳报告中标记为“ isNew” =“ true”的问题是否确实已更改(对于changedLinesOnly = true)或位于您要检查的提交中的更改文件中(对于changedLinesOnly = false)。

Another possible reason is the project configuration settings. 另一个可能的原因是项目配置设置。 If your files are part of a submodule, you'll need to include the submodule name to project base directories set . 如果文件是子模块的一部分,则需要在项目基本目录set中包含子模块名称 Or you may want to try a feature "allow auto match" instead. 或者,您可能想尝试“允许自动匹配”功能。 The feature tries to match SonarQube modules to Gerrit names automatically (available since 2.1). 该功能尝试自动将SonarQube模块与Gerrit名称匹配(从2.1开始可用)。


Not related to your question advises regarding your pipeline code: 与您的问题无关的建议与您的管道代码有关:

At the moment settings recognition for severity (and other enum values) is case-sensitive. 目前,设置的严重性(和其他枚举值)区分大小写。 In fact, the plugin ignores your "Major" setting as it cannot recognize it, and replaces it with default "INFO" value. 实际上,该插件会忽略您的“主要”设置,因为它无法识别该设置,并将其替换为默认的“ INFO”值。

Another thing, I don't see why do you set your "postScore" to true as you set "issuesScore" = 0 and "noIssuesScore"=0. 另一件事,当您将“ issuesScore”设置为0且“ noIssuesScore” = 0时,我不明白为什么将“ postScore”设置为true。 You can just set postScore=false and skip these settings along with "category" for sake of simplicity. 为了简单起见,您只需设置postScore = false并跳过这些设置以及“类别”即可。

Also, if you use the version of plugin above 2.0, be aware that API has slightly changed and now uses the next structure: 另外,如果您使用的插件版本高于2.0,请注意API稍有更改,现在使用下一个结构:

sonarToGerrit (
        reviewConfig: [ 
            issueFilterConfig: [
                severity: 'MAJOR', 
                newIssuesOnly: false, 
                changedLinesOnly: false
                ], 
            noIssuesTitleTemplate: 'Your text here',
            someIssuesTitleTemplate: 'Your text here',
            issueCommentTemplate: 'Your text here'
        ]
    )

Though your code should also work (plugin does support previous versions), there is a bigger chance that there may be a bug. 尽管您的代码也应该可以工作(插件确实支持以前的版本),但是有更大的机会可能会出现错误。

I am also facing the same issue with Sonar-Gerrit jenkins plugin. Sonar-Gerrit jenkins插件也面临同样的问题。 Downloaded it from Jenkins plugins site.Using Sonar-Gerrit plugin 2.2.1, and analysing sonar scan against jenkins workspace. 从Jenkins插件网站下载了它,使用Sonar-Gerrit插件2.2.1,并针对jenkins工作区分析声纳扫描。

For a sample,have changed just one file and provided the project base directory to the path of that file, and ran the sonar analysis in issues mode. 作为示例,仅更改了一个文件,并在该文件的路径中提供了项目基本目录,并在问题模式下运行了声纳分析。

Issues are not loaded in Gerrit with logs Gerrit未将问题加载到日志中

Report has loaded and contains 759 issues Issues to be commented: 0 Issues to be involved in score calculation: 0 Review has been sent 报告已加载并包含759个问题要评论的问题:0分数计算中涉及的问题:0已发送审阅

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM