【问题标题】:WARN: Protobuf file not found, when using SonarQube警告:使用 SonarQube 时未找到 Protobuf 文件
【发布时间】:2017-07-06 14:48:26
【问题描述】:

我刚刚开始使用 SonarQube,它运行至今。 IT 部门为我们的 Team Foundation Server 设置了 SonarQube 6.2,我已经在我的 BuildAgent 上安装并配置了 msbuild 扫描器。

我在构建定义的 XAML 模板中调用 msbuild 扫描程序,它确实运行,但它给了我一个警告,这使我的构建“部分成功”。 这是错误信息:

07:53:01.658 警告:找不到 Protobuf 文件: d:\b\210\474.sonarqube\out\ReferenceManager_x86_Release_6561\output-cs\issues.pb

issues.pb 文件确实丢失了,但为什么我会收到错误/警告?我不明白这一点,当我从命令行运行扫描仪和 msbuild 时,只有在团队构建中运行时。但是在命令行上运行时也没有issues.pb文件。

从命令行运行扫描仪时,我得到以下输出:

09:34:05.959 INFO: 97 files indexed
09:34:05.985 INFO: Quality profile for cs: Sonar way
09:34:05.992 DEBUG: Code colorizer, supported languages: 
09:34:07.008 DEBUG: 'Generic Coverage Report' skipped because one of the required properties is missing
09:34:07.009 DEBUG: 'Generic Test Executions Report' skipped because one of the required properties is missing
09:34:07.018 DEBUG: 'SurefireSensor' skipped because there is no related file in current project
09:34:07.023 DEBUG: 'JaCoCoSensor' skipped because there is no related file in current project
09:34:07.025 DEBUG: 'JavaSquidSensor' skipped because there is no related file in current project
09:34:07.025 DEBUG: 'JavaScript Squid Sensor' skipped because there is no related file in current project
09:34:07.027 DEBUG: Sensors : Lines Sensor -> SCM Sensor -> C# -> Coverage Report Import -> Coverage Report Import -> Unit Test Results Import -> XmlFileSensor -> Zero Coverage Sensor -> Code Colorizer Sensor -> CPD Block Indexer
09:34:07.029 INFO: Sensor Lines Sensor
09:34:07.279 INFO: Sensor Lines Sensor (done) | time=250ms
09:34:07.279 INFO: Sensor SCM Sensor
09:34:07.279 INFO: SCM Publisher is disabled
09:34:07.281 INFO: Sensor SCM Sensor (done) | time=2ms
09:34:07.281 INFO: Sensor C#
09:34:07.292 INFO: SonarAnalyzer.Scanner needs to be executed: false
09:34:07.292 INFO: Importing analysis results from C:\Users\Build-SW-Dev\Desktop\.sonarqube\out\ReferenceManager_x86_Release_5730\output-cs
09:34:08.749 INFO: Importing Roslyn report
09:34:08.998 INFO: Sensor C# (done) | time=1717ms

在团队构建期间运行扫描仪时,我得到以下输出:

11:12:51.390 INFO: 97 files indexed
11:12:51.422 INFO: Quality profile for cs: Sonar way
11:12:51.422 DEBUG: Code colorizer, supported languages: 
11:12:52.468 DEBUG: 'Generic Coverage Report' skipped because one of the required properties is missing
11:12:52.468 DEBUG: 'Generic Test Executions Report' skipped because one of the required properties is missing
11:12:52.468 DEBUG: 'SurefireSensor' skipped because there is no related file in current project
11:12:52.468 DEBUG: 'JaCoCoSensor' skipped because there is no related file in current project
11:12:52.468 DEBUG: 'JavaSquidSensor' skipped because there is no related file in current project
11:12:52.468 DEBUG: 'JavaScript Squid Sensor' skipped because there is no related file in current project
11:12:52.484 DEBUG: Sensors : Lines Sensor -> SCM Sensor -> C# -> Coverage Report Import -> Coverage Report Import -> Unit Test Results Import -> XmlFileSensor -> Zero Coverage Sensor -> Code Colorizer Sensor -> CPD Block Indexer
11:12:52.484 INFO: Sensor Lines Sensor
11:12:52.562 INFO: Sensor Lines Sensor (done) | time=78ms
11:12:52.562 INFO: Sensor SCM Sensor
11:12:52.562 INFO: SCM Publisher is disabled
11:12:52.562 INFO: Sensor SCM Sensor (done) | time=0ms
11:12:52.562 INFO: Sensor C#
11:12:52.562 INFO: SonarAnalyzer.Scanner needs to be executed: false
11:12:52.562 INFO: Importing analysis results from d:\b\210\474\.sonarqube\out\ReferenceManager_x86_Release_1481\output-cs
11:12:53.078 WARN: Protobuf file not found: d:\b\210\474\.sonarqube\out\ReferenceManager_x86_Release_1481\output-cs\issues.pb
11:12:53.718 INFO: Sensor C# (done) | time=1156ms

使用 google 未找到有关此错误的任何信息。任何帮助表示赞赏!

【问题讨论】:

  • 您使用的是哪个版本的 TFS?通常,警告不会导致您的构建部分成功,您有特定的设置吗?
  • 我们使用的是 TFS 2015 和 xaml 构建模板。我在 XAML 模板的测试部分的构建后部分中调用“MSBuild.SonarQube.Runner.exe end”,如她所述:github.com/SonarSource-VisualStudio/sonar-.net-documentation/… TFS 将此警告转换为错误:在测试运行器 09 之后运行可选脚本:41:38.799 WARN: Protobuf file not found: d:\b\210\474\.sonarqube\out\ReferenceManager_x86_Release_4068\output-cs\issues.pb 当你在 VS 中查看日志时,这里用红色叉号标记。 ..

标签: tfs msbuild sonarqube sonarqube-scan


【解决方案1】:

通过查看 CSharpSencor.java 中的代码,我认为命令行构建和团队构建之间的差异是由 RoslynReportPath 引起的:

void executeInternal(SensorContext context) {
  boolean requiresAnalyzerScannerExecution = !config.isReportsComingFromMSBuild();

  LOG.info("SonarAnalyzer.Scanner needs to be executed: " + requiresAnalyzerScannerExecution);

  String roslynReportPath = settings.getString(config.getRoslynJsonReportPathProperty());
  boolean hasRoslynReportPath = roslynReportPath != null;

  Path protobufReportsDirectory;
  if (requiresAnalyzerScannerExecution) {
    // MSBuild 12 or MSBuild 14 with old scanner
    analyze(!hasRoslynReportPath, context);
    protobufReportsDirectory = protobufReportPathForMSBuild12(context);
  } else {
    protobufReportsDirectory = config.protobufReportPathFromScanner();
  }

  LOG.info("Importing analysis results from " + protobufReportsDirectory.toAbsolutePath().toString());
  importResults(context, protobufReportsDirectory, !hasRoslynReportPath);

  if (hasRoslynReportPath) {
    LOG.info("Importing Roslyn report");
    importRoslynReport(roslynReportPath, context);
  }
}

命令行构建:

...
Generating SonarQube project properties file to C:\Users\Build-SW-Dev\Desktop\.sonarqube\out\sonar-project.properties
The supplied Code Analysis ErrorLog file is a valid json file and does not need to be fixed: d:\b\210\474\src\TPA\DevTools_Source\internal\ReferenceManager\main\ReferenceManager\bin\Release\ReferenceManager.exe.RoslynCA.json
...
08:41:57.276 INFO: Sensor C#
08:41:57.291 INFO: SonarAnalyzer.Scanner needs to be executed: false
08:41:57.291 INFO: Importing analysis results from C:\Users\Build-SW-Dev\Desktop\.sonarqube\out\ReferenceManager_x86_Release_6194\output-cs
08:41:59.948 INFO: Importing Roslyn report
08:42:00.448 INFO: Sensor C# (done) | time=3172ms

团队建设:

...
Generating SonarQube project properties file to d:\b\210\474\.sonarqube\out\sonar-project.properties
No Code Analysis ErrorLog file found at d:\b\210\474\bin\ReferenceManager.exe.RoslynCA.json.
...
11:12:52.562 INFO: Sensor C#
11:12:52.562 INFO: SonarAnalyzer.Scanner needs to be executed: false
11:12:52.562 INFO: Importing analysis results from d:\b\210\474\.sonarqube\out\ReferenceManager_x86_Release_1481\output-cs
11:12:53.078 WARN: Protobuf file not found: d:\b\210\474\.sonarqube\out\ReferenceManager_x86_Release_1481\output-cs\issues.pb
11:12:53.718 INFO: Sensor C# (done) | time=1156ms

虽然我还没有解决方案,但解决方法是将 msbuild 扫描程序的输出重定向到一个文件中。然后 TFS 看不到警告并且不会使构建部分成功。

编辑: 现在我找到了根本原因 :) 在团队构建期间,所有输出文件都被脚本移动到子文件夹中。这就是 SonarQube 找不到文件 'd:\b\210\474\bin\ReferenceManager.exe.RoslynCA.json' 的原因。 该文件位于子文件夹中...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-07-25
    • 1970-01-01
    • 2015-09-19
    • 2012-03-11
    • 2012-06-11
    • 1970-01-01
    • 2015-07-23
    • 1970-01-01
    相关资源
    最近更新 更多