SonarQube REST API:读取单个项目的指标 [英] SonarQube REST APIs : Read Metrics for individual projects

查看:49
本文介绍了SonarQube REST API:读取单个项目的指标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题:

我正在使用 SonarQube 7.1 版并尝试提取与单个项目相关的指标和质量门.

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

我们的尝试

在我们公司升级到版本 7.1 之前,我们使用 Python SonarQube API 来提取这些数据."api/resources" web service 自 sonarqube5.4 起已弃用,因此我们不能再使用它了.

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.

我也尝试过通过 Web API 使用 CURL 命令获取数据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'
我们能够获取单个指标的 json 有效负载,但涉及到每次创建 URL 的繁琐任务.

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.

推荐答案

你可以这样做:

首先调用 API api/metrics/search 以获取所有指标的 (json) 列表,然后遍历该列表并创建所有指标键的逗号分隔字符串.

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.

例如:ncloc,complexity,violations .. 如 API 文档中的参数示例值所述 这里.

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

然后您可以将此逗号分隔的列表作为参数添加到 url,例如:http://MY_HOST/api/measures/component?metricKeys=ncloc,complexity,violations&component=project_key

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.

另外,我还没有尝试过,但是根据最新的文档,参数 component 是可选的.因此,如果您忽略它,理想情况下您应该得到包含所有项目指标的响应.

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.

这篇关于SonarQube REST API:读取单个项目的指标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆