从Sonarqube API访问质量门状态 [英] Access quality gate status from sonarqube api
问题描述
我想通过SonarQube Web API获取SonarQube中项目质量门的当前状态,但是看不到质量门作为文档中的可用指标。
I would like to obtain the current status of the quality gate for my projects in SonarQube via the SonarQube web api, but I do not see quality gate as an available metric in the documentation. What is the best way to access this information to include in a report?
我正在使用的最佳方法是什么? SonarQube API可以访问有关项目分析的信息。 API的输出用于生成每周报告。我可以通过以下SonarQube API调用访问有关每个项目的信息。
I am using the SonarQube API to access information about project analyses. The output from the API is used to generate a weekly report. I can access the information about each project with the following SonarQube API call.
http://my-sonar-site/api/resources/index/?resource=$PROJECT_KEY&metrics=$METRIC_LIST
度量标准列表是从
http上的SonarQube API文档://docs.sonarqube.org/display/SONAR/Metric+definitions
除了质量状态外,这给了我我想要的一切
This gets me everything I want with the exception of the status of the quality gate.
- 我已经看过上面链接中的度量文档,但未能在api的那部分中找到质量门状态。
- 我还查看了 http://nemo.sonarqube.org/api_documentation#api/qualitygates -但是质量门API似乎用于创建和管理质量门和项目关联,而不是根据每个项目获取门的当前状态。
- I have looked through the documentation for metrics at the above link, but failed to find quality gate status in that part of the api.
- I have also looked at the quality gate API documented at http://nemo.sonarqube.org/api_documentation#api/qualitygates - but the quality gate API seems to be used for creating and managing quality gates and project associations rather than obtaining the current status of the gate on a per-project basis.
推荐答案
您可以使用 quality_gate_details度量标准来检索所需内容。以Nemo为例: http: //nemo.sonarqube.org/api/resources/index/?resource=org.codehaus.sonar:sonar&metrics=quality_gate_details
You can retrieve what you want with the "quality_gate_details" metric. As an example on Nemo: http://nemo.sonarqube.org/api/resources/index/?resource=org.codehaus.sonar:sonar&metrics=quality_gate_details
[{"id":48569,"key":"org.codehaus.sonar:sonar","name":"SonarQube","scope":"PRJ","qualifier":"TRK","date":"2014-11-30T16:13:17+0000","creationDate":null,"lname":"SonarQube","version":"5.0-SNAPSHOT","description":"Open source platform for continuous inspection of code quality","msr":[{"key":"quality_gate_details","data":"{\"level\":\"ERROR\",\"conditions\":[{\"metric\":\"blocker_violations\",\"op\":\"GT\",\"error\":\"0\",\"actual\":\"3.0\",\"level\":\"ERROR\"},{\"metric\":\"critical_violations\",\"op\":\"GT\",\"error\":\"0\",\"actual\":\"15.0\",\"level\":\"ERROR\"},{\"metric\":\"test_failures\",\"op\":\"GT\",\"warning\":\"0\",\"error\":\"\",\"actual\":\"0.0\",\"level\":\"OK\"},{\"metric\":\"skipped_tests\",\"op\":\"GT\",\"warning\":\"0\",\"actual\":\"0.0\",\"level\":\"OK\"},{\"metric\":\"coverage\",\"op\":\"LT\",\"warning\":\"\",\"error\":\"80\",\"actual\":\"81.5\",\"level\":\"OK\"},{\"metric\":\"test_errors\",\"op\":\"GT\",\"warning\":\"0\",\"error\":\"\",\"actual\":\"0.0\",\"level\":\"OK\"},{\"metric\":\"sqale_effort_to_grade_a\",\"op\":\"GT\",\"warning\":\"\",\"error\":\"0\",\"actual\":\"0.0\",\"level\":\"OK\"}]}"}]}]
现在,要获取指标的完整列表,可以浏览指标数据库表。
随时观看 https://jira.codehaus.org/browse/SONAR-5378 应该可以直接在SonarQube Web界面上提供详细的指标列表。
For now, to get a full list of metrics, you can browse the "metrics" database table. Feel free to watch https://jira.codehaus.org/browse/SONAR-5378 that should make the detailed list of metrics available directly on the SonarQube web interface.
这篇关于从Sonarqube API访问质量门状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!