问题描述
我已经设置了我们的 CI 工具(Teamcity),每次在 Github 中发出拉取请求时,都会对项目运行 SonarQube 预览分析。为了测试一切是否正常,我在提交拉取请求之前向代码库添加了一些问题。预览分析运行没有任何问题,拉取请求更新为摘要中的以下内容:
“ sonarqube — SonarQube 没有报告任何问题”
问题是我在代码库中引入的新问题都没有写成拉取请求的内联注释。
调试步骤和日志
我第二次运行预览分析,将sonar.verbose属性设置为true以将日志级别设置为 DEBUG。
我使用 Teamcity 中的 MSBuild Runner 执行分析的命令如下:
MSBuild.SonarQube.Runner.exe begin /k:<project_key> /n:"<project_name>" /v:%build.number% /d:sonar.analysis.mode=preview /d:sonar.github.oauth="<personal_access_token>" /d:sonar.github.pullRequest="<hard_coded_PR_no>" /d:sonar.github.repository="<organization>/<repo_name>" /d:sonar.issuesReport.console.enable=true /d:sonar.verbose=true
当分析运行时,我可以从日志中看到 SonarQube 正在处理这些问题(请参阅下面的日志)。因此,工作后 Github Pull Request Issue Publisher 似乎存在问题。以下是日志的摘录:
Working dir: D:\BuildAgent\work\<some_hash>\.sonarqube\out\.sonar
[08:57:01][Step 8/11] INFO: Source encoding: UTF-8, default locale: en_US
[08:57:01][Step 8/11] INFO: Sensor XmlFileSensor
[08:57:01][Step 8/11] INFO: Sensor XmlFileSensor (done) | time=0ms
[08:57:01][Step 8/11] INFO: Load server issues
[08:57:01][Step 8/11] INFO: Load server issues (done) | time=117ms
[08:57:01][Step 8/11] INFO: Performing issue tracking
[08:57:01][Step 8/11] INFO: 552/552 components tracked
[08:57:01][Step 8/11] INFO: Console report is deprecated. Use SonarLint CLI to have local reports of issues
[08:57:01][Step 8/11] INFO:
[08:57:01][Step 8/11]
[08:57:01][Step 8/11] ------------- Issues Report -------------
[08:57:01][Step 8/11]
[08:57:01][Step 8/11] +15 issues
[08:57:01][Step 8/11]
[08:57:01][Step 8/11] +4 blocker
[08:57:01][Step 8/11] +1 critical
[08:57:01][Step 8/11] +10 major
[08:57:01][Step 8/11]
[08:57:01][Step 8/11] -------------------------------------------
[08:57:01][Step 8/11]
[08:57:01][Step 8/11]
[08:57:01][Step 8/11] INFO: ANALYSIS SUCCESSFUL
[08:57:01][Step 8/11] INFO: Executing post-job GitHub Pull Request Issue Publisher
[08:57:02][Step 8/11] INFO: ------------------------------------------------------------------------
[08:57:02][Step 8/11] INFO: EXECUTION SUCCESS
[08:57:02][Step 8/11] INFO: ------------------------------------------------------------------------
[08:57:02][Step 8/11] INFO: Total time: 35.242s
[08:57:02][Step 8/11] INFO: Final Memory: 48M/172M
[08:57:02][Step 8/11] INFO: ------------------------------------------------------------------------
[08:57:03][Step 8/11] The SonarQube Scanner has finished
[08:57:03][Step 8/11] 08:57:03.022 Creating a summary markdown file...
[08:57:03][Step 8/11] 08:57:03.023 Analysis results: http://<sonarqube_server>/dashboard/index/<project_name>
[08:57:03][Step 8/11] Post-processing succeeded.
[08:57:03][Step 8/11] Process exited with code 0
Github 设置
我在我的用户上添加了一个个人访问令牌,用作sonar.github.oauth属性的输入。我的用户对有问题的 repo 拥有所有权限。该令牌已被赋予“public_repo”范围,以便能够根据文档编写内联评论并更新拉取请求- 只有前者永远不会完成。
插件和工具的版本
- SonarQube 5.6
- C# 插件(版本 5.3.2)
- MSBuild Runner 插件(1.1 版)
- Github 插件(1.3 版)
- TeamCity(版本 9.1.7)
- Github 企业版(2.7 版)
我错过了什么?我还没有尝试过的一件事是创建一个专门的技术 Github 用户,而不是使用我自己的用户和个人访问令牌。这可能是导致问题的原因吗?