我在将依赖检查器输出从构建代理发送到 SonarQube 服务器时遇到问题。我不确定它是我与依赖检查器一起使用的命令还是服务器/客户端上的 SonarQube 设置。我将 .cs、.js、.css 等的扫描输出报告到 SonarQube 中。但是依赖项扫描的输出在依赖项检查器小部件中不可见。但是,如果我检查特定构建的工作文件夹,则会从 owasp 依赖项检查器创建的三个文件尚未被拾取。
在进行扫描之前我所做的准备工作:
- 从https://jeremylong.github.io/DependencyCheck/dependency-check-cli/index.html下载 OWASP dependency-check-cli
- 将 OWASP dependency-check-cli 提取到一个目录,并将 Path 作为环境值添加到构建代理服务器上
- 通过标记的位置在 SonarQube 上安装了依赖检查器插件
- 通过构建代理服务帐户在构建代理服务器上安装了 sonarscanner
- 从 SonarQube 的依赖检查插件的报告字段中删除了 ${Workspace}/ 值
- 该值现在只是dependency-check-report.html/json/xml(待在字段上)。
我用来通过 .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,并在依赖检查后面添加 /src/ -report.xml
声纳扫描仪结束命令:
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.
如果我删除了工作目录,那么它在 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 中报告的依赖项时,视图为空。我错过了什么..?
输出在那里: