Leveraging Sonarqube API's to extract project related information

web_api

(Naveen Arora) #1

Hi

I am currently using SonarQube v6.7, I am looking to get the following information using API’s -

  1. List of sonarqube projects
  2. Lines of code per project
  3. Application / Portfolio that the project is associated with?

I tried exploring api/components and api/measures but that wasn’t of much help.
Any suggestions will be much appreciated.

Regards
Naveen


(Julien Lancelot) #2

Hi Naveen,

You’ll find below the answer of your questions.

  1. List of sonarqube projects

api/components/search?qualifiers=TRK

  1. Lines of code per project

api/measures/component?component=<PROJECT_KEY>&metricKeys=ncloc

  1. Application / Portfolio that the project is associated with?

This information is not available in this way, you can only get the list of projects from a Portfolio or Application :
api/components/tree?component=<APPLICATION_OR_PORTFOLIO_KEY>&qualifiers=TRK&strategy=children

Regards


(Naveen Arora) #3

Thanks Julien, with the mentioned queries from you, I was able to get the information but in silos, I probably need to write a script in order to get one consolidated report for the above 3 points. Is there a database query that can simply give the above information in a single report?

Regards
Naveen


(Colin Mueller) #4

Naveen,

Running queries against a production database actively serving an application is not a good idea — and the SonarQube database should be treated as a black box: it is not publicly documented and it can change at anytime from version to version without warning.

Our Web APIs however have clear documentation available as well as consistent deprecation strategies when they are altered (a deprecated parameter will, for example, still be available for 2 major versions post-deprecation before being removed). Assuming you want to run your report more than once across multiple versions of SonarQube, this is very important!

I strongly encourage using the Web APIs.

Colin


(Naveen Arora) #5

Okay, point taken Colin.
Thanks for the prompt reply and recommendations.