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.
Enter the basic data.
Use the size you like. I chose DS12.
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.
The default port for Sonar is 9000 – but you can use any port you want.
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.
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.
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.
Edit the Environment Variable “Path” and append “;%JAVA_HOME%” to it.
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).
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 sonar.properties 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!
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.
Star the service. Open a browser and open “http://localhost:9000/”. If everything went well you should see the sonar home screen:
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.
Also consider changing your security profile. Sonar is public by default.
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.
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.