DarkMatter in Cyberspace
  • Home
  • Categories
  • Tags
  • Archives

Get SonarQube Metrics Results with Web Service


Debug Sonar Web Service

curl 'http://localhost:9000/api/resources?resource=841&metrics=coverage,ncloc,test_success_density,packages' where resource is id or key of sonar project.

Reference: Web Service /api/resources

Retrieve data via python script

python script:

import urllib2 
import json 
sonarUrl = 'http://localhost:9000/api/resources?resource=841&metrics=ncloc,classes,violations,coverage,tests,test_success_density,comment_lines_density,duplications_data,function_complexity' 
conn = urllib2.urlopen(sonarUrl) 
data = json.load(conn) 
print json.dumps(data, indent=2) 

Retrieve data via groovy script

import groovy.json.JsonSlurper 
sonarUrl = 'http://10.0.2.74:9000/api/resources?resource=841&metrics=ncloc,' +

   'classes,violations,coverage,tests,test_success_density,' + 
   'comment_lines_density,duplications_data,function_complexity' 
def conn = new URL(sonarUrl).getText() 
def data = new JsonSlurper().parseText(conn) 
println data.id 
println data.lname 
println data.msr 

You can insert this script into "Pre-send Script" section of email-ext plugin of Jenkins to retrieve sonar analysis result.

Set of metrics key: http://docs.sonarsource.org/2.5/apidocs/org/sonar/gwt/Metrics.html



Published

Jul 3, 2013

Last Updated

Jul 3, 2013

Category

Tech

Tags

  • json 7
  • Python 136
  • sonar 17
  • web service 1

Contact

  • Powered by Pelican. Theme: Elegant by Talha Mansoor