【发布时间】:2018-09-02 02:05:56
【问题描述】:
我正在升级 TeamCity 2017.1.4 和 SonarQube 6.7.1,并且正在升级分析方法以使用 Sonar Scanner for MsBuild (4.0.2) 而不是之前使用的 Sonar Runner。
我们使用 MsBuild 脚本,以便我们可以对更改进行源代码控制,我正在努力让声纳扫描仪工作。
问题似乎是当我使用 MSBuild 任务构建项目时,Sonar 抱怨说它尚未构建或不是使用较新版本的 MsBuild 构建的。 但是,如果我使用 Exec 命令指定构建,它会正确处理所有内容。
使用 Exec 运行 MsBuild(不是我想做的):
<Exec Command="$(SonarScannerMSBuildPath) begin /d:sonar.verbose=$(SonarScannerVerboseLogging) /k:"$(SonarProjectKey)" /n:"$(SonarProjectName)" /v:"$(Build_Number)"" />
<Exec Command=""C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\msbuild.exe" @(Solution) /t:Rebuild" />
<Exec Command="$(SonarScannerMSBuildPath) end" />
我想使用的命令是,因为这应该使用在 TeamCity 中选择的 MsBuild 版本:
<Exec Command="$(SonarScannerMSBuildPath) begin /d:sonar.verbose=$(SonarScannerVerboseLogging) /k:"$(SonarProjectKey)" /n:"$(SonarProjectName)" /v:"$(Build_Number)"" />
<MSBuild Targets="Rebuild" Properties="Configuration=Debug" Projects="@(Solution)" />
<Exec Command="$(SonarScannerMSBuildPath) end" />
在 TeamCity 中,我将 MsBuild 版本设置为:
我注意到,当我运行 Exec 命令来构建解决方案时,我看到了分析器警告,但是当通过 MsBuild 命令运行构建时,这些警告不会出现。 teamcity 输出表明正在使用正确的 MsBuild 版本:
[11:40:34] [Step 1/1] Starting: D:\TeamCity\buildAgent\plugins\dotnetPlugin\bin\JetBrains.BuildServer.MsBuildBootstrap.exe /workdir:D:\TeamCity\buildAgent\work\488e6f245ac98af3 "/msbuildPath:C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\bin\MSBuild.exe"
错误信息说明:
[12:23:07] [Exec] The SonarQube MSBuild integration failed: SonarQube was unable to collect the required information about your projects.
[12:23:07] [Exec] Possible causes:
[12:23:07] [Exec] 1. The project has not been built - the project must be built in between the begin and end steps
[12:23:07] [Exec] 2. An unsupported version of MSBuild has been used to build the project. Currently MSBuild 14.0 upwards are supported
[12:23:07] [Exec] 3. The begin, build or end steps have not all been launched from the same folder
如果我浏览到 TeamCity 构建代理上的文件夹,我会丢失 .sonar 和 .sonarqube 文件夹。
【问题讨论】:
标签: c# sonarqube teamcity sonarqube-scan