SonarQube REST APIs : Read Metrics for individual projects

梦想的初衷 提交于 2020-03-17 11:24:11

问题


My question:

I am using SonarQube version 7.1 and trying to extract the metrics and quality gate related to individual projects.

What we have tried

We were using Python SonarQube API to extract these data before our company upgraded to version 7.1. "api/resources" web service Deprecated since sonarqube5.4, so we cannot use it anymore.

I have also tried using getting data using CURL command via Web API using curl -i -H "Content-Type: application/json" -H "x-api-key:token" -X GET 'http://MY_HOST/api/measures/component?metricKeys=key&component=project_key'
We are able to get a json payload for individual metrics, but involves tedious task of creating the URL every single time.

But I wanted to know if there is a better/smarter way to access these "measures", be it any language or implementation.


回答1:


You could do this:

Call the API api/metrics/search first to get a (json) list of all the metrics and then iterate over that list and create a comma separated string of all the metric keys.

For example something like this: ncloc,complexity,violations .. as mentioned in the parameters example value in the API documentation here.

Then you could just add this comma separated list to the url as a parameter something like: http://MY_HOST/api/measures/component?metricKeys=ncloc,complexity,violations&component=project_key

and call it once to get the response for all metrics.

Also, I haven't tried this, but as per the latest documentation, the parameter component is optional. So if you omit that, ideally you should get a response with metrics of all the projects.



来源:https://stackoverflow.com/questions/51526635/sonarqube-rest-apis-read-metrics-for-individual-projects

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!