本文总结目前两种常用的生成 SonarQube 结果报告的方法,以备查阅。
适用SonarQube版本 : 5.5--7.5。
官网地址:https://gitee.com/zzulj/sonar-pdf-plugin
本插件生成 PDF 格式的 sonarqube 报告.
报告包括以下内容:
SONARQUBE_HOME/extensions/plugins
目录SonarQube PDF 是一个 post-job任务. 因此,PDF 报告将在SonarQube 分析结束后生成.
配置 Skip 为“否”时生成 PDF 报告功能启用。
配置 Username 和 Password。如果出现 HTTP error: 401 或者 HTTP error: 403, msg: Forbidden,请查看该配置。
5.x版本:PDF 在仪表盘中下载,如果没有下载界面,需要在“配置控件”中添加该控件
6.x 以及 7.x 版本:因为 UI 变化无仪表盘页面,在工程中 More 菜单下查看:
生成的报告内容如下:
插件可以将代码分析从 SonarQube 服务器导出为 docx、xlsx、csv、markdown 和文本文件。
该工具可以作为 JAR 可执行文件(使用命令行)或作为 Sonarqube 插件独立使用。
特性:
官网地址:https://github.com/cnescatlab/sonar-cnes-report
/opt/sonarqube/extensions/plugins
,重启 sonarqube,然后点击 “More”>“CNES Report”。Cnesreport 不需要任何安装。它是一个可移植的 Java 应用程序,可以根据下面的示例复制并运行它。唯一的要求是一个最新的JRE(>=1.8)。
sonar-cnes-report.jar
复制到 sonarqube 的插件文件夹中(在 linux 上路径应该是这样的 /opt/sonarqube/extensions/plugins
)sudo service sonar restart
)使用 java -jar cnesreport.jar -h
以获取有关 cnesreport 以下帮助:
usage: java -jar cnesreport.jar [-a <arg>] [-b <arg>] [-c] [-d <arg>] [-e] [-h] [-l <arg>] [-o <arg>] [-p <arg>] [-r <arg>]
[-s <arg>] [-t <arg>] [-v] [-w] [-x <arg>]
Generate editable reports for SonarQube projects.
-a,--author <arg> Name of the report writer.
-b,--branch <arg> Branch of the targeted project. Requires Developer Edition or sonarqube-community-branch-plugin. Default: usage of main branch.
-c,--disable-conf Disable export of quality configuration used during analysis.
-d,--date <arg> Date for the report. Format: yyyy-MM-dd. Default: current date.
-e,--disable-spreadsheet Disable spreadsheet generation.
-f,--disable-csv Disable csv generation.
-h,--help Display this message.
-l,--language <arg> Language of the report. Values: en_US, fr_FR. Default: en_US.
-m,--disable-markdown Disable markdown generation.
-n,--template-markdown <arg> Path to the report template in markdown. Default: usage of internal template.
-o,--output <arg> Output path for exported resources.
-p,--project <arg> SonarQube key of the targeted project.
-r,--template-report <arg> Path to the report template. Default: usage of internal template.
-s,--server <arg> Complete URL of the targeted SonarQube server.
-t,--token <arg> SonarQube token of the SonarQube user who has permissions on the project.
-v,--version Display current version.
-w,--disable-report Disable report generation.
-x,--template-spreadsheet <arg> Path to the spreadsheet template. Default: usage of internal template.
Please report issues at https://github.com/cnescatlab/sonar-cnes-report/issues
如果正在使用 SonarQube 的安全实例,可以通过 -t 选项提供一个 SonarQube 身份验证令牌,并使用 -s 指定 SonarQube 实例的url。文本报告的内部模板将被 -r 选项所取代。
java -Xmx1024m -Xms1024m -jar sonar-cnes-report.jar -t 6bc36088524a4d06e3e07e73ba419127cd90ff04 -s http://172.16.106.188:9088/ -p projectId -r template.docx
生成的文件如下:
打开其中 word 的报告:
有关遗留版本,请在这里查看 wiki 页面 : Note on legacy versions
通过简单的实验,我发现 sonar-cnes-report
报告的数据较 Sonar PDF Report Plugin
更为正确,推荐使用前者。