用于 .Net Framework 和 .Net Core 的 TeamCity 和 SonarQube 依赖项检查器

Dependency Checker with TeamCity and SonarQube for .Net Framework and .Net Core

我在将构建代理的依赖项检查器输出发送到 SonarQube 服务器时遇到问题。 我不确定这是我在 Dependency Checker 中使用的命令还是服务器/客户端上的 SonarQube 设置。我将 .cs、.js、.css 等的扫描输出报告到 SonarQube 中。但是依赖性扫描的输出在依赖性检查器小部件中不可见。但是,如果我检查特定构建的工作文件夹,则有三个文件是从 owasp 依赖项检查器创建的,但尚未被提取。

扫描前我做了哪些准备:

我用来通过.Net Core安装dotnet-sonarscanner的命令:

dotnet tool install --global dotnet-sonarscanner

OWASP dependency-check-cli 命令(运行 来自构建代理上 checkoutDir 的根目录):

dependency-check.bat --project "%system.teamcity.projectName%" --scan . -f ALL --log D:\DependencyLogs\verbose.log

为了让 RetireJs 功能正常工作,我不得不调试日志并直接下载无法直接检索的 json 文件。我想我还需要使用 java 参数 (/d:)

为 https 的代理添加覆盖

声纳扫描仪开始命令:

dotnet sonarscanner begin /k:%ProjectKey% /n:"%ProjectName%" /d:sonar.login=%SonarQube.UserToken% /d:sonar.host.url=%SonarQube.Host.Url%"

如果我f.ex添加参数/d:sonar.dependencyCheck.xmlReportPath=%system.teamcity.checkoutDir%/dependency-check-report.xml,它被解析为checkoutdir在 dependency-check-report.xml

后面添加 /src/

Sonar Scanner 结束命令:

dotnet sonarscanner /d:sonar.login=%SonarQube.UserToken% end

如果我加上

%system.teamcity.build.workingDir%/dependency-check-report.html

到sonarqube插件属性中的html、xml或json字段:

[23:19:08]  [Step 1/1] INFO: Dependency-Check JSON report does not exists. Please check property sonar.dependencyCheck.jsonReportPath:D:\TeamCityBuildAgent\work\a7450333ae6fcf0c\%system.teamcity.build.workingDir%\dependency-check-report.json
[23:19:08]  [Step 1/1] INFO: JSON-Analysis skipped/aborted due to missing report file
[23:19:08]  [Step 1/1] INFO: Using XML-Reportparser
[23:19:08]  [Step 1/1] INFO: Dependency-Check XML report does not exists. Please check property sonar.dependencyCheck.xmlReportPath:D:\TeamCityBuildAgent\work\a7450333ae6fcf0c\%system.teamcity.build.workingDir%\dependency-check-report.xml
[23:19:08]  [Step 1/1] INFO: XML-Analysis skipped/aborted due to missing report file
[23:19:08]  [Step 1/1] INFO: Dependency-Check HTML report does not exists. Please check property sonar.dependencyCheck.htmlReportPath:D:\TeamCityBuildAgent\work\a7450333ae6fcf0c\%system.teamcity.build.workingDir%\dependency-check-report.html
[23:19:08]  [Step 1/1] INFO: HTML-Dependency-Check report does not exist.

如果我删除了 workingdir,那么它在 sonarqube 中看起来像这样:

dependency-check-report.html

输出如下所示:

[23:26:38]  [Step 1/1] INFO: Sensor Dependency-Check [dependencycheck]
[23:26:38]  [Step 1/1] INFO: Process Dependency-Check report
[23:26:38]  [Step 1/1] INFO: Using JSON-Reportparser
[23:26:39]  [Step 1/1] WARN: JSON-Analysis aborted
[23:26:39]  [Step 1/1] INFO: Using XML-Reportparser
[23:26:39]  [Step 1/1] INFO: We doesn't found any Project configuration file e.g. pom.xml, gradle.build, build.gradle.kts, package-lock.json and can not link dependencies
[23:26:39]  [Step 1/1] INFO: Linking 662 dependencies to project
[23:26:39]  [Step 1/1] INFO: Upload Dependency-Check HTML-Report
[23:26:39]  [Step 1/1] INFO: Process Dependency-Check report (done) | time=959ms
[23:26:39]  [Step 1/1] INFO: Sensor Dependency-Check [dependencycheck] (done) | time=960ms

所以这应该有效。 Dependency-Check HTML 完成并上传,但是当我查看SonarQube中报告的依赖项时,视图是空的。我错过了什么..?

虽然输出在那里:

目前 SonarQube 的官方插件(版本 2.0.2)有一个不显示 html 结果的错误。

如果你想让它工作,你目前需要从这个分支获取最新的快照 https://github.com/dependency-check/dependency-check-sonar-plugin/tree/rewrite_javascript