SonarQube Runner Setup

1. Get SonarQube Runner

1.1 Visit the archived runner page to get runner-2.4, compatible up to SonarQube 5.5; if you are installing a newer version of SonarQube, then visit SonarQube official site for the latest version (renamed as sonar-scanner)

1.2 Download the required version for Windows to your Downloads folder

2. Extracts to C:\sonarqube

2.1 Extracts the downloaded file to C:\sonarqube\runner-2.4 using your preferred unzip program

3. Define system variables

3.1 Open system properties dialog

3.2 Select Advanced System Settings

3.3 Click on Environment Variables... button

3.4 On the Envirnoment Variable dialog, click on system variables New... button

3.5 Define the SONAR_RUNNER_HOME variable

3.6 Accept changes and edit the system variable Path to add ;%SONAR_RUNNER_HOME%\bin at the end

3.7 Accept changes and close all dialogs

3.8 Depending on you Windows version, you need to restart to apply the changes

4. Setup SonarQube Runner properties

4.1 Configure your database driver and the username/password to connect to database

%SONAR_RUNNER_HOME%\conf\sonar-runner.properties
#Configure here general information about the environment, such as SonarQube DB details for example
#No information about specific project should appear here

#----- Default SonarQube server
#sonar.host.url=http://localhost:9000
sonar.core.serverBaseURL=http://localhost:9000

#----- PostgreSQL
sonar.jdbc.url=jdbc:postgresql://localhost/sonar

#----- MySQL
#sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8

#----- Oracle
#sonar.jdbc.url=jdbc:oracle:thin:@localhost/XE

#----- Microsoft SQLServer
#sonar.jdbc.url=jdbc:jtds:sqlserver://localhost/sonar;SelectMethod=Cursor

#----- Global database settings
sonar.jdbc.username=sonar
sonar.jdbc.password=<database-password>

#----- Default source code encoding
#sonar.sourceEncoding=UTF-8

#----- Security (when 'sonar.forceAuthentication' is set to 'true')
#sonar.login=admin
#sonar.password=admin

5. Quick check

5.1 A quick sonar-runner check

> sonar-runner --version
C:\sonarqube\runner-2.4
SonarQube Runner 2.4
Java 1.8.0_111 Oracle Corporation (64-bit)
Windows NT (unknown) 10.0 amd64

1. Get SonarQube Runner

1.1 Visit the archived runner page to get runner-2.4, compatible up to SonarQube 5.5; if you are installing a newer version of SonarQube, then visit SonarQube official site for the latest version (renamed as sonar-scanner)

1.2 Download the latest version via wget command to /tmp folder

$ wget -P /tmp http://repo1.maven.org/maven2/org/codehaus/sonar/runner/sonar-runner-dist/2.4/sonar-runner-dist-2.4.zip

2. Extracts to /opt/sonarqube/

2.1 Extracts the downloaded file to /opt/sonarqube/runner-2.4

$ sudo unzip /tmp/sonar-runner-dist-2.4.zip -d /opt/sonarqube

$ ls -la /opt/sonarqube/sonar-runner-2.4
total 20
drwxr-xr-x 5 root  root  4096 Apr 24  2014 .
drwxr-xr-x 5 sonar sonar 4096 Jan  2 15:08 ..
drwxr-xr-x 2 root  root  4096 Apr 24  2014 bin
drwxr-xr-x 2 root  root  4096 Apr 24  2014 conf
drwxr-xr-x 2 root  root  4096 Apr 24  2014 lib

3. Define a symbolic link to SonarQube Runner

3.1 For easy upgrades on future it is highly recommended to create the symbolic link

$ sudo ln -s /opt/sonarqube/sonar-runner-2.4 /opt/sonarqube/sonar-runner

4. Setup SonarQube Runner properties

4.1 Configure your database driver and the username/password to connect to database

/opt/sonarqube/sonar-runner/conf/sonar-runner.properties
#Configure here general information about the environment, such as SonarQube DB details for example
#No information about specific project should appear here

#----- Default SonarQube server
#sonar.host.url=http://localhost:9000
sonar.core.serverBaseURL=http://localhost:9000

#----- PostgreSQL
sonar.jdbc.url=jdbc:postgresql://localhost/sonar

#----- MySQL
#sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&amp;characterEncoding=utf8

#----- Oracle
#sonar.jdbc.url=jdbc:oracle:thin:@localhost/XE

#----- Microsoft SQLServer
#sonar.jdbc.url=jdbc:jtds:sqlserver://localhost/sonar;SelectMethod=Cursor

#----- Global database settings
sonar.jdbc.username=sonar
sonar.jdbc.password=<database-password>

#----- Default source code encoding
#sonar.sourceEncoding=UTF-8

#----- Security (when 'sonar.forceAuthentication' is set to 'true')
#sonar.login=admin
#sonar.password=admin

5. Add SonarQube Runner to PATH

5.1 If you want to execute SonarQube Runner from command line, it is recommended to add to your PATH

~/.profile
JAVA_HOME=/opt/java/default-jdk/
export JAVA_HOME
SONAR_RUNNER_HOME=/opt/sonarqube/sonar-runner
export SONAR_RUNNER_HOME
PATH="$JAVA_HOME/bin:$SONAR_RUNNER_HOME/bin:$PATH"
export PATH