Setup SonarQube in Azure VM

If you have installed and integrated SonarQube once in TFS 2012 you know it was really painful. But a lot of things have changed and now it’s really easy to setup a new SonarQube instance in Azure and integrate it into you build process and in Visual Studio. I did it this week and it was really fast and straight forward.

Setup a machine in Azure

I wanted to have a machine for trainings and demos. That’s why I decided to use SQL Server 2014 on Windows 2012 R2. Like this I can turn the machine on and of easily.

New Azure VM

SQL Server 2014 SP1 image

Enter the basic data.

Vm Basic Data

Use the size you like. I chose DS12.

VM Size

Use the default values for the rest of the dialog and provision the machine.

Open Port in Network Security Group

In classic mode you had to define endpoints for your virtual Machines. This concept does not exist any more. Now you have to go to the network security group that was provisioned with you VM and add an inbound rule.

Add inbound rule

The default port for Sonar is 9000 – but you can use any port you want.

Inbound rule properties

It’s not longer required to open a port to the sql server to integrate Sonar in your CI process. So with the one port open we are done here.

Create Sonar Database

First create a new windows user in computer management. The sonar service will later run with this account and access the database using windows authentication.

Create sonat database

Now open Management Studio and create a new database. Set the collation to “Latin1_General_100_CS_AS” and the recovery model to “Simple”.


Create a login for the new user and make him db owner of the new database.

Create sonar login

Install Java JDK

Download the latest version of Java and install it. Note were the JDK was installed. In my case it is “C:\Program Files\Java\jdk1.8.0_91”. Now go to “Advanced system settings” and create a new Environment Variable  JAVA_HOME the points to your JDK path.

Install JDK

Edit the Environment Variable “Path” and append “;%JAVA_HOME%” to it.

Set Path variable

Next download the JDBC Driver package. Extract the 64 bit version of sqljdbc_auth.dll from the archive. Make sure that it is “unblocked” and copy it to a folder in your “Path” environment variable (I used the java home).

Install SonarQube

Download the latest version of SonarQube (currently 5.4). Unblock the archive and copy the output to your target folder (i.e. C:\Sonar). Open in the conf folder and look for the “Microsoft SQLServer” section. Uncomment the sonar.jdbc.url line and make sure your database name is correct.

As my friend Colin pointed out, the connection string is case sensitive. Make sure that you database name has the correct casing!

Configure SonarQube

If you want to run Sonar on Port 9000 your are done. Otherwise look for the property “sonar.web.port” and change it.

Open a command prompt as an administrator, go to \bin\windows-x86-64 inside your Sonar folder and run InstallNTService.bat. Because sonar service depends on the sql server we have to set this dependency.

sc config SonarQube depend=MSSQLSERVER

Open services.msc and locate the service SonarQube. Set the log on account to the windows user you created and that is db owner of your sonar database.

Set Account for SonarQube Service

Star the service. Open a browser and open “http://localhost:9000/”. If everything went well you should see the sonar home screen:

Local Homescreen

If there are errors look in the event log and the sonar log.

Log in as “admin” with the password “admin”. Change the password under My Account –> Security.

Change admin password

Also consider changing your security profile. Sonar is public by default.

Modify security profile

To access sonar from the public endpoint we also have to open the port in the windows firewall. Add a rule to the firewall

netsh advfirewall firewall add rule name=Sonar dir=in action=allow protocol=TCP localport=9000

That’s it now. You should now be able to browse sonar over your public address and log in with your admin account.

Public home screen

In the next post I will integrate sonar in a Visual Studio Team Service build and use SonarLint to integrate SonarQube in your Visual Studio project.

5 thoughts on “Setup SonarQube in Azure VM

  1. Great article! Just a suggestion, windows account must have required right on the folder otherwise the service is not starting

    1. For trainings and demos yes. For real projects we now use But yes – I should have mentioned that. Do you have a good source that I can link to?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s