Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SonarQube - Is there an API to grab a part of analysis for all projects you have?

I want to be able to extract, for example, just the Technical Debt numbers out of my sonar instance for all the projects I have, and display them on a page.

Does Sonar provide an api that I can utilize and achieve this?

like image 288
Drumroll Avatar asked Mar 18 '16 18:03

Drumroll


1 Answers

SonarQube lets you get exhaustive data using its Web API. Taking your example of project's measures:

Since SonarQube 5.4

Use api/measures Web API (see parameters in documentation). Example for project postgresql:

  • Get the component ID:

    https://nemo.sonarqube.org/api/components/show?key=postgresql

  • Get the desired metrics:

    https://nemo.sonarqube.org/api/measures/component?componentId=6d75286c-42bb-4377-a0a1-bfe88169cffb&metricKeys=sqale_debt_ratio&additionalFields=metrics,periods

Before SonarQube 5.4

Use api/resources Web API:

http://sonarqube_url/api/resources?resource=your_resource&metrics=metric_key

Listing metric keys

Use api/metrics/search (documented here), see also Metric Definitions.

like image 168
Nicolas B. Avatar answered Sep 20 '22 13:09

Nicolas B.