1

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?

slartidan
  • 20,403
  • 15
  • 83
  • 131
A Porter
  • 25
  • 4

2 Answers2

1

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

slartidan
  • 20,403
  • 15
  • 83
  • 131
  • Thank you @slartidan, i have implemented your suggestion and it works well. Though i am also going to look into the below Massimo suggestion – A Porter Jul 11 '17 at 22:43
-2

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

Massimo Borgogno
  • 117
  • 1
  • 1
  • 4
  • Thank you @Massimo Borgogno, i will give your suggestion a go – A Porter Jul 11 '17 at 22:44
  • I have confirmed that SonarQube 6.3, released a few months before your post, and 6.5, released after your post, both have the 10k limit on /api/issues/search. If for some reason you know of a setting or workaround to remove this limit please let me know and I'll upvote you :-) – Paul Jan 11 '18 at 18:24