Monday, 15 December 2014

Configure Jenkins for Android - Sonar

Sonar is a Stand alone server which could be used to analyse the code. Jenkins has specific plugin for Sonar which could trigger sonar to do the code analysis for each build.

1. Download and install Sonar
The first thing to do is download and install Sonar. In its wiki it has a good tutorial about how to download and run it. Just go to the follow page and install Sonar, Sonar runner and try to run it with the sample project:

2. Install plugins for Jenkins
2.1 From the main page of Jenkins, go to "Manage Jenkins" -> "Manage Plugins" -> Available
2.2 Look for a Plugin called "Sonar Plugin" and check the checkbox
2.3 At the bottom of the screen, click on "Download and install after restart"
2.4 On the new screen, check "Restart Jenkins when installation is complete and no jobs are running"

3. Configure Jenkins
Before run the project, Jenkins must be configured to know where is Sonar and the Sonar runner.
3.1 From the main page of Jenkins, go to "Manage Jenkins" -> "Configure system"
3.2 Look for Sonar block, fill the name. It could be as simple as "Sonar"
3.3 In the same block, click on "Advanced"
3.4 Fill the field "Server URL" with the url of the Sonar, it is usually:


3.5 In the same page, look for Sonar Runner block and click on "Sonar Runner Installations"
3.6 Set the name for the Sonar Runner. It could be "Sonar runner"
3.7 In the field "SONAR_RUNNER_HOME", set the path to Sonar runner, which has been downloaded and tested in the first step.
It is also possible install a new version of Sonar Runner by check the checkbox "Install automatically" and set the version of Sonar Runner. The new Sonar Runner will be installed in the SONAR_RUNNER_HOME directory.

4. Configure the job
4.1 In the configuration of the project, in the "Add build step", select "Invoke Standalone Sonar Analysis"
4.2 Let the field "Task to run" blank
4.3 Config JDK = (Inherit From Job)
4.4 There are two ways to config the project properties:
    - By creating a file which contains all the properties
    - By setting the properties directly in the configuration of Jenkins

4.4.1 To save the properties in a file, you must add it to the repository and config the field "Path to project properties". Leave the field "Project properties" unfilled.
4.4.2 To set the properties directly, leave the filed "Path to project properties" unfilled, and use the field "Project properties" to set the properties.
Here is some clue about how to fill the fields and what properties they could have:


No comments:

Post a Comment