Access status of quality access from sonarqube api

My question is:

I would like to get the current quality caliber status for my projects in SonarQube via the SonarQube web app, but I don't see the quality gate as an available metric in the documentation. What is the best way to access this information for inclusion in a report?

History:

I am using SonarQube API to access project analysis information. The exit from the API is used to generate a weekly report. I can access information about each project with the following SonarQube API call.

http://my-sonar-site/api/resources/index/?resource=$PROJECT_KEY&metrics=$METRIC_LIST

      

The list of metrics is populated from the SonarQube API documentation at

http://docs.sonarqube.org/display/SONAR/Metric+definitions

This gives me everything I want except for the quality caliber status.

What I have tried:

  • I have looked through the metrics documentation from the above link but could not find the quality status in this api part.
  • I also looked at the gate quality API documented at http://nemo.sonarqube.org/api_documentation#api/qualitygates - but the quality gate API seems to be used to create and manage gate quality and project associations rather than getting the current state of the gate by every project.
+3


source to share


2 answers


You can get 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\"}]}"}]}]

      



Now, for a complete list of metrics, you can view the "metrics" database table. Feel free to look at https://jira.codehaus.org/browse/SONAR-5378 , which should make the detailed list of metrics available directly on the SonarQube web interface.

+4


source


Since SonarQube 5.3 you can get the Qualitygate status using the API:    http: // [sonarhost] / api / qualitygates / project_status? AnalyzesId = [ID]



Since SonarQube 5.4:    http: // [sonarhost] / api / qualitygates / project_status? ProjectKey = [key]

+14


source







All Articles