SonarQube - C#代码未显示在仪表板上

时间:2018-02-28 15:41:32

标签: c# sonarqube

我遇到SonarQube 6.7的问题,它没有显示任何C#代码问题或错误,在分析过程中我可以看到正在分析C#并且构建成功但是当我检查SonarQube仪表板时它只显示了Typescript和XML。

我正在使用Jenkins使用Mono构建项目,因为我们的所有构建都在Ubuntu 16.04上完成。

设置如下:

Jenkins 2.89.2在Ubuntu 16.04上

在Ubuntu 16.04(独立服务器)上的SonarQube版本6.7(内部版本33306)

声纳C#6.8.1

适用于MSBuild 4.0.1的SonarQube扫描仪

单声道5.10.0稳定

使用管道在Jenkins中我正在执行以下操作:

node {
    sh 'mono ~/tools/hudson.plugins.sonar.MsBuildSQRunnerInstallation/MSBuild/SonarQube.Scanner.MSBuild.exe begin /key:12345678FAKEKEY9l02998745'
    sh 'dotnet restore WSP1.sln'
    sh 'dotnet msbuild WSP1.sln'
    sh 'mono ~/tools/hudson.plugins.sonar.MsBuildSQRunnerInstallation/MSBuild/SonarQube.Scanner.MSBuild.exe end' } }

上面的管道脚本没有任何问题。

当我运行这个管道时,我可以看到C#代码正在被分析,这只是一个被分析的代码片段:

Services/Project1/Services/Project1EventsShould.cs(130,21): warning S1186: Add a nested comment explaining why this method is empty, throw a 'NotSupportedException' or complete the implementation. [/var/lib/jenkins/workspace/CSharpAnalysis/WSP1/test/Unit/Unit.csproj]
Services/Project1/Services/Project1EventsShould.cs(137,21): warning S1186: Add a nested comment explaining why this method is empty, throw a 'NotSupportedException' or complete the implementation. [/var/lib/jenkins/workspace/CSharpAnalysis/WSP1/test/Unit/Unit.csproj]
Services/Project1/Models/ZenEventShould.cs(24,17): warning S1481: Remove this unused 'date' local variable. [/var/lib/jenkins/workspace/CSharpAnalysis/WSP1/test/Unit/Unit.csproj]
Services/Project1/Models/CollaborationUserShould.cs(16,17): warning S1481: Remove this unused 'sut' local variable. [/var/lib/jenkins/workspace/CSharpAnalysis/WSP1/test/Unit/Unit.csproj]

最后我获得了成功,一切看起来都不错但是当我查看SonarQube时,我可以看到上传的代码正在分析以便在SonarQube中显示,这通常需要一分钟左右但是当这完成时我可以看到仅显示TypeScript和XML。

在输出中我收到一些警告,信息和错误,但没有什么看起来很险恶,在输出结束时我得到了成功消息

INFO: 68 files had no CPD blocks
INFO: Calculating CPD for 281 files
INFO: CPD calculation finished
INFO: Analysis report generated in 1771ms, dir size=5 MB
INFO: Analysis reports compressed in 3908ms, zip size=2 MB
INFO: Analysis report uploaded in 5866ms
INFO: ANALYSIS SUCCESSFUL, you can browse http://sonar.serverdomain.com:9000/dashboard/index/12345678FAKEKEY9l02998745
INFO: Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report
INFO: More about the report processing at http://sonar.serverdomain.com:9000/api/ce/task?id=AKsdHc7FAKEIDVOeCzBYv
INFO: Task total time: 1:32.107 s
INFO: ------------------------------------------------------------------------
INFO: EXECUTION SUCCESS
INFO: ------------------------------------------------------------------------
INFO: Total time: 1:42.735s
INFO: Final Memory: 54M/397M
INFO: ------------------------------------------------------------------------
The SonarQube Scanner has finished
14:59:57.577  Creating a summary markdown file...
14:59:57.59  Analysis results: http://sonar.serverdomain.com:9000/dashboard/index/12345678FAKEKEY9l02998745
14:59:57.591  Post-processing succeeded.
Finished: SUCCESS

我有完整的输出方便,我只需要清理它以删除任何可能敏感的东西,如果你想看看只是告诉我,我会发布这个。

我对SonarQube很陌生,所以我遇到的问题可能是愚蠢的,但我一直在试图解决这个问题。

编辑:我正在挖掘输出,并在下面注意到2个警告:

INFO: Quality profile for cs: Sonar way
INFO: Quality profile for ts: Sonar way
INFO: Quality profile for xml: Sonar way
INFO: Sensor C# Properties [csharp]
WARNING: WARN: Property missing: 'sonar.cs.analyzer.projectOutPaths'. No protobuf files will be loaded for this project.
WARNING: WARN: No roslyn issues report not found for this project.
INFO: Sensor C# Properties [csharp] (done) | time=1ms

1 个答案:

答案 0 :(得分:0)

我刚刚在Sonarqube 6.7.4(build 38452)上遇到了同样的问题。

通过两个步骤解决:

  1. 将内置的SonarC#插件更新到版本7.2(内部版本5463)(卸载 - 重新启动 - 安装 - 重启),然后重新扫描,出现代码问题(漏洞,代码异味等)。
  2. 将软件包coverlet.msbuild引入测试项目以生成覆盖率数据,配置项目 - 管理 - C# - OpenCover单元测试报告路径以使用path/to/coverage.opencover.xml。重新扫描后,测试覆盖率数据出现了。
  3. 以下是在上述配置之后执行的所有命令:

        dotnet path/to/SonarScanner.MSBuild.dll begin /k:"project-key"
        dotnet build
        dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=opencover
        dotnet path/to/SonarScanner.MSBuild.dll end