简体   繁体   English

SonarQube MSBuild与Jenkins的集成失败,在命令行上工作正常

[英]SonarQube MSBuild integration failed with Jenkins, works fine on command line

I am analyzing my .NET project with sonarqube and I want to automate it with my jenkins build server. 我正在用声纳分析我的.NET项目,我想用我的jenkins构建服务器将其自动化。

I use 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 我使用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

I tried the jenkins "SonarQube Scanner for MSBuild - Begin Analysis" and "SonarQube Scanner for MSBuild - End Analysis" build steps but they failed with the following error message: 我尝试了jenkins“用于MSBuild的SonarQube扫描仪-开始分析”和“用于MSBuild的SonarQube扫描仪-结束分析”的构建步骤,但是它们失败并显示以下错误消息:

The SonarQube MSBuild integration failed: SonarQube was unable to collect the required information about your projects. SonarQube MSBuild集成失败:SonarQube无法收集有关您的项目的必需信息。 Possible causes: 可能的原因:

  1. The project has not been built - the project must be built in between the begin and end steps 该项目尚未构建-必须在开始和结束步骤之间构建该项目
  2. An unsupported version of MSBuild has been used to build the project. 使用了不支持的MSBuild版本来生成项目。 Currently MSBuild 14.0 upwards are supported 当前支持MSBuild 14.0或更高版本
  3. The begin, build or end steps have not all been launched from the same folder 尚未从同一文件夹启动所有开始,构建或结束步骤

I tried a couple of things and then switched to a windows batch file build step with the following content: 我尝试了几件事,然后切换到具有以下内容的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%"

Because this is the most minimal example I could think of. 因为这是我能想到的最简单的例子。 It still fails: 它仍然失败:

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 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

The interesting part is, when I open a command line, switch to the jenkins workspace and then execute the commands manually everything works as expected: 有趣的是,当我打开命令行时,切换到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.

Any hints how to debug this? 有什么提示如何调试吗? I can provide additional logs and information if you need them. 如果需要,我可以提供其他日志和信息。

I could kind of resolve this issue. 我可以解决这个问题。 I am not 100% happy but I can make this work by calling SonarQube.Scanner.MSBuild.exe and MSBuild.exe with the full absolute path: 我不是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%"

But I can't figure out why this works but calling them from the %PATH% env doesn't. 但是我不知道为什么会这样,但是从%PATH%env调用它们却没有。 It is really weird... 真的很奇怪

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

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