Installation

SonarQube

_$: wget http://dist.sonar.codehaus.org/sonarqube-4.3.1.zip
_$: unzip sonarqube-4.3.1.zip
_$: mv sonarqube-4.3.1 /etc/sonarqube

SonarQube Runner

_$: wget http://repo1.maven.org/maven2/org/codehaus/sonar/runner/sonar-runner-dist/2.4/sonar-runner-dist-2.4.zip
_$: unzip sonar-runner-dist-2.4.zip
_$: mv sonar-runner-2.4 /etc/sonar-runner

Python plugin

_$: wget http://repository.codehaus.org/org/codehaus/sonar-plugins/python/sonar-python-plugin/1.3/sonar-python-plugin-1.3.jar
_$: mv sonar-python-plugin-1.3.jar /etc/sonarqube/extensions/plugins

Database creation

(postgres@host)_$: createuser -P sonarqube
(postgres@host)_$: createdb -O sonarqube sonarqube

Configuration

/etc/sonarqube/conf/sonar.properties:
-------------------------------------
...
sonar.jdbc.username=sonarqube
sonar.jdbc.password=SheBTUW5
...
sonar.jdbc.url=jdbc:postgresql://localhost/sonarqube
/etc/sonar-runner/conf/sonar-runner.properties:
-----------------------------------------------
...
sonar.jdbc.url=jdbc:postgresql://localhost/sonarqube
...
sonar.jdbc.username=sonarqube
sonar.jdbc.password=SheBTUW5

Run SonarQube

Test it as a standalone:

_$: /etc/sonarqube/bin/linux-x86-64/sonar.sh start
Starting SonarQube...
Started SonarQube.
_$: /etc/sonarqube/bin/linux-x86-64/sonar.sh status
SonarQube is running (3729).
_$: /etc/sonarqube/bin/linux-x86-64/sonar.sh stop
Stopping SonarQube...
Stopped SonarQube.

As a service:

/etc/init.d/sonar:
------------------
#!/bin/sh
#
# rc file for SonarQube
#
# chkconfig: 345 96 10
# description: SonarQube system (www.sonarsource.org)
#
### BEGIN INIT INFO
# Provides: sonar
# Required-Start: $network
# Required-Stop: $network
# Default-Start: 3 4 5
# Default-Stop: 0 1 2 6
# Short-Description: SonarQube system (www.sonarsource.org)
# Description: SonarQube system (www.sonarsource.org)
### END INIT INFO

/usr/bin/sonar $*
_$: export SONAR_HOME=/etc/sonarqube
_$: ln -s $SONAR_HOME/bin/linux-x86-64/sonar.sh /usr/bin/sonar
_$: chmod 755 /etc/init.d/sonar
_$: update-rc.d sonar defaults
_$: service sonar start && service sonar status
SonarQube is running (4286).

Go to http://localhost:9000 and check that it is running.

Environment variables

Run the following commands with the same user that will run sonar-runner

_$: export SONAR_RUNNER_HOME=/etc/sonar-runner
_$: export PATH=$PATH:$SONAR_RUNNER_HOME/bin
_$: env | grep PATH
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/etc/sonar-runner/bin

Code analysis

In one of Jenkins’ project, for instance, project_git create a file called sonar-project.properties.

/home/jenkins/.jenkins/jobs/taloki_git/workspace/sonar-project.properties:
--------------------------------------------------------------------------
# Required metadata
sonar.projectKey=taloki
sonar.projectName=taloki
sonar.projectVersion=1.0

#path to files where to start analyzing.
sonar.sources=taloki

# Encoding of the source code
sonar.sourceEncoding=UTF-8

sonar.language=py

If you haven’t already, export the environment variables:

_$: export SONAR_RUNNER_HOME=/etc/sonar-runner
_$: export PATH=$PATH:$SONAR_RUNNER_HOME/bin

Run sonar-runner:

_$: cd /home/jenkins/.jenkins/jobs/taloki_git/workspace
_$: sonar-runner

Go to http://localhost:9000/dashboard/index/project and check that it is ok.