我正在用sonarqube分析我的.NET项目,我想用我的jenkins构建服务器自动化它。
我使用MSBuild 14.0.23107.0,sonarqube 6.7.1.35068,sonar-scanner-msbuild-4.0.2.892,sonar-csharp-plugin-6.7.1.4347,Jenkins 2.89.3
我尝试了jenkins" SonarQube Scanner for MSBuild - Begin Analysis"和#34;用于MSBuild的SonarQube扫描仪 - 结束分析"构建步骤但它们失败并显示以下错误消息:
SonarQube MSBuild集成失败:SonarQube无法进行 收集有关您项目的必要信息。可能的原因:
- 项目尚未建成 - 项目必须建立在开始和结束步骤之间
- 已使用不受支持的MSBuild版本来构建项目。目前支持MSBuild 14.0以上
- 开始,构建或结束步骤尚未从同一文件夹启动
醇>
我尝试了几件事,然后切换到Windows批处理文件构建步骤,其中包含以下内容:
SonarQube.Scanner.MSBuild.exe begin /k:"eGate" /v:"%SVN_REVISION%" /d:sonar.login="%SONAR_AUTH_TOKEN%"
MSBuild.exe /property:Configuration=AutoBuild /t:Rebuild
SonarQube.Scanner.MSBuild.exe end /d:sonar.login="%SONAR_AUTH_TOKEN%"
因为这是我能想到的最小的例子。它仍然失败:
12:41:39 C:\Jenkins\workspace\eGate>SonarQube.Scanner.MSBuild.exe begin /k:"eGate" /v:"8503" /d:sonar.login="******"
12:41:39 SonarQube Scanner for MSBuild 4.0.2
12:41:39 Default properties file was found at C:\sonarqube\bin\SonarQube.Analysis.xml
12:41:39 Loading analysis properties from C:\sonarqube\bin\SonarQube.Analysis.xml
12:41:39 Pre-processing started.
12:41:39 Preparing working directories...
12:41:39 12:41:39.232 Updating build integration targets...
12:41:39 12:41:39.243 Fetching analysis configuration settings...
12:41:39 12:41:39.403 Provisioning analyzer assemblies for cs...
12:41:39 12:41:39.404 Installing required Roslyn analyzers...
12:41:39 12:41:39.44 Pre-processing succeeded.
12:41:39
12:41:39 C:\Jenkins\workspace\eGate>MSBuild.exe /property:Configuration=AutoBuild /t:Rebuild
12:41:39 Microsoft (R)-Buildmodul, Version 14.0.23107.0
SNIP
12:42:28
12:42:28 4 Warnung(en)
12:42:28 0 Fehler
12:42:28
12:42:28 Verstrichene Zeit 00:00:48.97
12:42:28
12:42:28 C:\Jenkins\workspace\eGate>SonarQube.Scanner.MSBuild.exe end /d:sonar.login="******"
12:42:28 SonarQube Scanner for MSBuild 4.0.2
12:42:28 Default properties file was found at C:\sonarqube\bin\SonarQube.Analysis.xml
12:42:28 Loading analysis properties from C:\sonarqube\bin\SonarQube.Analysis.xml
12:42:28 Post-processing started.
12:42:28 The SonarQube MSBuild integration failed: SonarQube was unable to collect the required information about your projects.
12:42:28 Possible causes:
12:42:28 1. The project has not been built - the project must be built in between the begin and end steps
12:42:28 2. An unsupported version of MSBuild has been used to build the project. Currently MSBuild 14.0 upwards are supported
12:42:28 3. The begin, build or end steps have not all been launched from the same folder
12:42:28 Generation of the sonar-properties file failed. Unable to complete SonarQube analysis.
12:42:28 12:42:28.73 Creating a summary markdown file...
12:42:28 12:42:28.732 Post-processing failed. Exit code: 1
12:42:28
12:42:28 C:\Jenkins\workspace\eGate>exit 1
12:42:28 Build step 'Windows Batch-Datei ausführen' marked build as failure
12:42:29 Finished: FAILURE
有趣的是,当我打开命令行时,切换到jenkins工作区,然后手动执行命令,一切按预期工作:
The SonarQube Scanner has finished
12:28:23.407 Creating a summary markdown file...
12:28:23.411 Analysis results: http://localhost:9000/dashboard/index/eGate
12:28:23.411 Post-processing succeeded.
任何提示如何调试这个?如果您需要,我可以提供额外的日志和信息。
答案 0 :(得分:0)
我可以解决这个问题。我并非100%满意,但我可以通过使用完整的绝对路径调用SonarQube.Scanner.MSBuild.exe和MSBuild.exe来完成这项工作:
"C:\sonarqube\bin\SonarQube.Scanner.MSBuild.exe" begin /k:"eGate" /v:"%SVN_REVISION /d:sonar.login="%SONAR_AUTH_TOKEN%"
"C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe" /property:Configuration=AutoBuild /t:Rebuild
"C:\sonarqube\bin\SonarQube.Scanner.MSBuild.exe" end /d:sonar.login="%SONAR_AUTH_TOKEN%"
但我无法弄清楚为什么这样可行,但是从%PATH%env调用它们却没有。这真的很奇怪......