Installing SonarQube Runner on Ubuntu

Prerequisites

SonarQube
DBMS (MySQL in my case)

Download and unzip SonarQube Runner distribution

Visit the SonarQube official site for the current version.

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 /opt/sonar-runner

Edit sonar-runner.properties

Open /opt/sonar-runner/conf/sonar-runner.properties in a text editor, and modify it.
Uncomment the following lines:

sonar.host.url=http://localhost:9000/sonar
sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8

sonar.jdbc.username=sonar
sonar.jdbc.password=sonar

The value of the sonar.host.url depends on your SonarQube Web Server settings located in /opt/sonar/conf/sonar.properties (See: Installing SonarQube on Ubuntu)

Create and set environment variables

Create ~/.pam_environment file if it does not exist:

touch ~/.pam_environment

Open ~/.pam_environment in a text editor, and add the following lines to it:

SONAR_RUNNER_HOME=/opt/sonar-runner
PATH DEFAULT=${PATH}:${SONAR_RUNNER_HOME}/bin

Re-login in order to initialize these changes, and check them with the following command:

sonar-runner -h

Run SonarQube Runner on a sample source

First localize the source code and binaries for analysis purposes, e.g.:

~/my_apps/my_project/src
~/my_apps/my_project/build/classes

Then create a configuration file for your project naming it sonar-project.properties:

touch ~/my_apps/my_project/sonar-project.properties

Open the file in a text editor, and add the following lines to it:

sonar.projectKey=my:project
sonar.projectName=My project
sonar.projectVersion=1.0
sonar.sources=src
sonar.binaries=build/classes
sonar.sourceEncoding=UTF-8

Start the SonarQube web server, and run SonarQube Runner from your project directory:

~/my_apps/my_project$ sonar-runner -X

After the process is done, open the SonarQube web page at http://localhost:9000/sonar, and check your project analysis within Projects panel.

REFERENCES

docs.sonarqube.org/display/SONARQUBE45/Installing+and+Configuring+SonarQube+Runner
qualilogy.com/en/install-sonarqube-first-analysis-with-sonarqube-runner/

Leave a Reply

Your email address will not be published. Required fields are marked *