警告:使用SonarQube时未找到Protobuf文件

时间:2017-02-17 07:23:30

标签: tfs msbuild sonarqube sonarqube-scan

我刚刚开始使用SonarQube,它确实运行到目前为止。 IT部门为我们的Team Foundation Server设置了SonarQube 6.2,我在BuildAgent上安装并配置了msbuild扫描程序。

我在构建定义的XAML-Template中调用了msbuild扫描程序并且它确实运行了,但它给了我一个警告,这使我的构建部分成功了#34;。 这是错误消息:

  

07:53:01.658警告:未找到Protobuf文件:   d:\ B \ 210 \ 474.sonarqube \出\ ReferenceManager_x86_Release_6561 \输出-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

使用谷歌没有找到任何关于此错误的信息。任何帮助表示赞赏!

1 个答案:

答案 0 :(得分:0)

通过查看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'。 该文件位于子文件夹中......