我在 SonarQube 分析过程中收到警告
Missing blame information for the following files
。
[INFO] [22:19:57.714] Sensor SCM Sensor
[INFO] [22:19:57.715] SCM provider for this project is: git
[INFO] [22:19:57.715] 48 files to be analyzed
[INFO] [22:19:58.448] 0/48 files analyzed
[WARN] [22:19:58.448] Missing blame information for the following files:
(snip 48 lines)
[WARN] [22:19:58.449] This may lead to missing/broken features in SonarQube
[INFO] [22:19:58.449] Sensor SCM Sensor (done) | time=735ms
我正在使用 SonarQube 5.5,分析是由 Maven 在 Jenkins 作业中在多模块 Java 项目上完成的。 Git 插件 1.2 已安装。
在 bash shell 中对任何有问题的文件手动运行 git Blame,都会得到预期的输出。
我发现的相关问题都是关于SVN的,我的问题是关于Git的。
如何获取 Sonarqube 上的 git Blame 信息?
原因是 JGit bug。 JGit 不支持
.gitattributes
。我的 ident
里有
.gitattributes
。普通控制台 git
检查了源代码,在 ident
宏上应用了 $Id$
,但随后 JGit 忽略了这一点,并看到了一个未提交的差异,实际上没有差异。
SonarQube 邮件列表上的友好人士帮助了我,并建议使用独立 JGit 命令行发行版进行调试:
chmod +x /where/is/org.eclipse.jgit.pgm-<version>-r.sh
/where/is/org.eclipse.jgit.pgm-<version>-r.sh blame -w /path/to/offending/file
这个特殊的 JGit 错误已经超过 5 年没有得到解决,我不希望它能很快得到解决,所以我从所有来源中删除了
$Id$
宏。这是我使用的(Bash)代码,用于删除所有
$Id$
宏:
find */src -name "*.java" | xargs -n 1 sed -i '/$Id.*$/d'
find */src -name "*.java" | xargs git add
git commit -m "Remove $Id$ macros"
git push
api.json
。在 Team City 中的 SonarQube 运行程序构建步骤中,我将此文件添加到附加参数中的排除项中
-Dsonar.exclusions=**/spec/api.json
错误消失了。
Missing blame information for the following files
。如果您在有未跟踪的文件或未提交的更改时运行
mvn sonar:sonar
,这些文件将被列为丢失的责任信息。现在我的项目在 SonarQube Web 界面中显示质量门失败,但下次在 CI 管道中运行分析时,该问题应该会消失。
Maven,这可能会对您有所帮助。
快速解决方案是在-Dsonar.scm.disabled=True
命令时添加此参数
sonar:sonar
。我在尝试向 sonarqube 服务器发送报告时遇到了同样的问题。 该警告表明有一些文件未提交,这有助于 sonarqube 的 diff 算法确定新的代码周期问题。
$ docker login artifactory.companyname.corp
之后,docker 将询问您的公司用户和密码
问题已解决