4

Appriciate if I can get help for the below scenario. My issues to identify how to extract/export all java rules on SonarQube 4.5.7. I tried the below two API calls but I get a "The page you were looking for doesn't exist".

The sonarqube version I have shows 781 java rules my objective is to extract them to an excel or a csv file

[1]curl -X GET -v -u admin:admin http://localhost:9000/api/rules?language=java

[2]curl -X GET -v -u admin:admin http://localhost:9000/api/rules/search?languages=java >> java.json

The second option seems to generate an output but not all 781 rules are extracted thanks,shavantha

G. Ann - SonarSource Team
  • 22,346
  • 4
  • 40
  • 76
shavantha
  • 361
  • 1
  • 2
  • 13

3 Answers3

11

URL api/rules/search?languages=java is the correct way to get all Java rules. Response is paginated, so only 10 rules are returned by default :

{ "total": 781, "p": 1, "ps": 10, "rules": [ <here are 10 rules ] }

Use pagination parameter p (page index) for traversing all results. Note that the page size can be changed with parameter ps (defaults 10).

Simon Brandhof
  • 5,137
  • 1
  • 21
  • 28
  • thank you it worked. I used REST client on add-on on firefox and extracted the details as : http://localhost:9000/api/rules/search?language=java&p=2&ps=100 – shavantha Dec 05 '16 at 11:22
5

Login as an Admin

then go to the Quality Profiles section

click which language rule set you want to copy

click on the settings like button at the side

then select copy and give a name to the copy

then in the next page click on the settings like button then click backup

your file will be exported in to your local in the XML format

Applicable for both Internet Sonar as well as Local

2

http://localhost:9000/api/rules/search?languages=java

the url parameter is languages rather language

java1977
  • 398
  • 4
  • 12
  • 25