How to retrieve all rules of a quality profile using the web api?

1.5k Views Asked by At

I have run a analysis on Sonarqube with Codescan. The number of issues returned, is way above the 10000 web api limit. Therefore, within my client/code I wanted to loop through all of the rules within a quality profile and return all the issues per rule.

How can I get a list of rules using the web api from java?

2

There are 2 best solutions below

1
On

You can use api/qualityprofiles/backup. It takes a quality profile key as parameter and returns an xml containing all "active rules".

2
On

Newer SonarQube versions do not have the 10K issues limitation.
You have to loop n-times to collect all results.
For example:
Consider a project with 44K issues.
You have to discover first how many issues you have to read, call one time the /api/issues/search with only you project key and the parameter ps ( pagesize ) equal to 100
http:///api/issues/search?componentKeys=&ps=100

You could receive an answer like this

{"total":44130,"p":1,"ps":100,"paging":{"pageIndex":1,"pageSize":100,"total":44130},"issues":[{"key":"AVtoCSNP6OwvnmtEJjae","ru..........

So we have to claim 44130 issues, using a pagesize of 100 then you must call (44130 / 100 ) + 1 times the /api/issues/search for your project and for every request remember to increase by 1 the p ( page ) parameter ( so you can point the right portion of results )

Your sequence of command will be like this

http:///api/issues/search?componentKeys=YOUR_PROJECT_KEY>&ps=100&p=1 http:///api/issues/search?componentKeys=YOUR_PROJECT_KEY>&ps=100&p=2 http:///api/issues/search?componentKeys=YOUR_PROJECT_KEY>&ps=100&p=3 .... http:///api/issues/search?componentKeys=YOUR_PROJECT_KEY>&ps=100&p=442

Parse the result of every call and you will be obtained the list of your issues.

Cheers

Massimo