当前位置:  开发笔记 > 编程语言 > 正文

Incorporate Sonar into Jenkins

SonarisaintegratedcodequalitytoolprimarilyforJAVA,butalsosupportotherlanguagessuchasjavascript,C#etc.withplugin.Jenkinsisthemostpopular"Continou

Sonar is a integrated code quality tool primarily for JAVA, but also support other languages such as javascript, C# etc. with plugin.


Jenkins is the most popular "Continous Integration" tool.

There're two way to incorporate Sonar as a build step into Jenkins job:  Standalone sonar runner  OR sonar-maven-plugin

(Here assumes you already installed Jenkins.)

Install Sonar
Need to install a sonar instance, download from http://www.sonarsource.org/downloads
start sonar service. E.g on a 64bit linux server, use:  
$ /bin/linux-x86-64/sonar.sh start

the you can access http://127.0.0.1:9000  as Sonar URL. Note: By default the built-in H2 database does not support other server to access this sonar instance remotely by the IP/URL, unless you manually config it to use your own database instance like mysql.
if you want to analyze javascript other than JAVA, download a sonar plugin:  http://docs.codehaus.org/display/SONAR/JavaScript+Plugin
download and install sonar-runner if you don't use sonar-maven-plugin:  http://docs.codehaus.org/display/SONAR/Installing+and+Configuring+Sonar+Runner
config sonar in Jenkins:  http://127.0.0.1:8080/jenkins/configure


A javascript project with standalone runner

add a post-build step of "Invoke Standalone Sonar Analysis"
in the Project properties field
assume you already use Cobertura running unit tests

# required metadata
sonar.projectKey=
sonar.projectName=
sonar.projectVersion=1.0.0

# path to source directories (required)
sonar.sources=

# Uncomment this line to analyse a project which is not a java project.
# The value of the property must be the key of the language.
sonar.language=javascript

 

A JAVA project with standalone runner
add a post-build step of "Invoke Standalone Sonar Analysis"
in the Project properties field
assume you already use Cobertura running unit tests, so to reuse the report


# required metadata
sonar.projectKey=
sonar.projectName=
sonar.projectVersion=1.0.0

# path to source directories (required)
sonar.sources=

# Uncomment this line to analyse a project which is not a java project.
# The value of the property must be the key of the language.
sonar.language=java

sonar.dynamicAnalysis=reuseReports
sonar.surefire.reportsPath=
sonar.core.codeCoveragePlugin=cobertura
sonar.cobertura.reportPath=/cobertura/coverage.xml

 

A JAVA(maven) project with sonar-maven-plugin

add below properties in pom.xml  (assume using emma but not reuse the report.  For other tool like jacoco, cobertura, see http://docs.codehaus.org/display/SONAR/Code+Coverage+by+Unit+Tests )
add a post-build action of "Sonar"

 
    UTF-8
    java
   
   
    true
   
   
    reports/junit
   
   
    emma
   
   
    reports/emma
 

推荐阅读
无名有名我无名_593
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有