DarkMatter in Cyberspace
  • Home
  • Categories
  • Tags
  • Archives

Code Quality Check based on Jenkins and Sonar


Based on Jenkins 1.5 with Sonar plugins, Ubuntu 12.04.

Installation and System Configuration

  • Install and config Jenkins: see note " Install Jenkins and plugins by hand ";

  • Install and config Sonar and Sonar Runner: see note " Analyze Java Code with Sonar on Ubuntu ";

Jenkins System Configuration

Manage Jenkins -> Configure System:

Sonar Runner: Name: MySonarRunner; SONAR_RUNNER_HOME: parent folder of "bin/sonar-runner" script;
Sonar -> Sonar Installations -> Advanced:
Name: MySonar;
Sonar account login/password: admin/admin;
Server URL: leave blank(http://localhost:9000, if sonar server is not at the same server with jenkins, notice no "/" at the end of this url);
Database URL: jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true(equals to "sonar.jdbc.url" in $SONAR_SERVER/conf/sonar.properties, notice "localhost" can not be writen as ip address);
Database login/password: sonar/sonar;
Database Driver: com.mysql.jdbc.Driver;

Project-specific Sonar Runner Configuration

Creating file /opt/sonar-server/gcp.properties as followings: see note " Analyze Java Code with Sonar on Ubuntu " and notice:

sonar.sources=src (a relative path name whose root directory is $PROJECT_WORKSPACE);
sonar.sourceEncoding=GBK (determined by source file encoding, default is UTF-8);

Jenkins Project Configuration

Source Code Management: Subversion -> enter subversion url;

Build:

Execute Shell: cp /opt/sonar-server/gcp.properties ./sonar-project.properties
Invoke Standalone Sonar Analysis

Do not add post-build actions "Sonar" because it's bounded with Maven. If there is no pom.xml at the root of the project, an error raises.



Published

May 20, 2013

Last Updated

May 20, 2013

Category

Tech

Tags

  • jenkins 26
  • sonar 17
  • ubuntu 61

Contact

  • Powered by Pelican. Theme: Elegant by Talha Mansoor