Thursday, 20 April 2017

SonarQube with Mysql Setup in Windows along with Steps to Project Analysis

SonarQube Server with Mysql Prerequisites:

Software Requirement:

  • Java (Oracle JRE 8 onwards or OpenJDK 8 onwards)
  • Mysql (5.6 or higher versions)
    • Use UTF-8 charset.
    • Only InnoDB Storage Engine.
    • mysql-connector-java jar is supported.
  • Web browser to Run http://localhost:9000 after SonarQube Installation and server Start.

Hardware Requirement:
1. 1GB of free RAM for the OS.
2. 2GB of RAM to run SonarQube Server.

Mysql Installation:
  • Download Mysql 5.6
  • Install Mysql.
  • Set Username and Password for the root.
  • Create a Database called "sonarqube"
  • Create a user called sonarqube with All Privileges on sonarqube database.

SonarQube Installation & Starting Server:
  • Download SonarQube 6.3 version.
  • Unzip Downloaded file.
  • Place SonarQube 6.3 folder at any place as per your convenient. 
  • I have kept that folder in D:/softwares/Sonar/ folder.
  • Open file in D:/softwares/Sonar/SonarQube 6.3/conf/ folder.
  • Un comment below lines and set Username and Password of Mysql (Line numbers - 14 & 15).
    • sonar.jdbc.username=sonarqube
    • sonar.jdbc.password=sonarqube
  • Un comment "sonar.jdbc.url" line related to MySQL 5.6 or greater comments (Line Number - 23) and set that line as below.
    • sonar.jdbc.url=jdbc:mysql://localhost:3306/sonarqube?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance&useSSL=false
  • Apart from those 3 lines, all other lines should be in commented mode. 
  • Based on your processor specific to OS, you will be having different BIT wise operation folders in BIN directory. in my case, i am using 32 bit processor. so, my folder name will be "windows-x86-32".
  • Start Sonar
    • There are 2 ways to start sonar.
      • Add Sonar specific *.bat files location in Environment Variable.
        • We can find different shell scripts files (*.bat) such as InstallNTService.bat, StartNTService.bat, StartSonar.bat etc in D:/softwares/Sonar/SonarQube 6.3/bin/<OS_BIT_Processor>/ folder.
        • Copy the path of this folder, which may look like D:\softwares\Sonar\sonarqube-6.3\bin\windows-x86-32, and append it to “Path” environment variable.
        • Open a command prompt, type “StartSonar” command and execute. This would start a web server at default port of 9000.
        • Open a web browser and access the page, http://localhost:9000.
      • Open a command prompt.
        • Move to OS_BIT_Processor folder.
          • D:\softwares\Sonar\sonarqube-6.3\bin>
          • Type “StartSonar.bat” command and execute. This would start a web server at default port of 9000.
        • Open a web browser and access the page, http://localhost:9000.
SonarQube Runner Setup
  • Download Sonar Runner.
  • Unzip Downloaded file.
  • Place sonar-runner-2.4 folder at any place as per your convenient. 
  • I have kept that folder in D:/softwares/Sonar/ folder.
  • Update the global settings (database connection, server URL) by editing file in D:/softwares/Sonar/sonar-runner-2.4/conf/ folder.
  • sonar-runner-2.4 file code should look like below.
  • set "SONAR_RUNNER_HOME" Environment variable which points to sonar-runner-2.4 folder.
    • Open Control Panel.
    • Click on System Link
    • Click on Advanced System Settings link on Left Navigation.
    • Click on Environment Variables button on System Properties window.
    • Under System Variables Create a New variable with below name and Value.
      • Variable Name-  SONAR_RUNNER_HOME
      • Variable Value-  D:\softwares\Sonar\sonar-runner-2.4\
    • Append this Environmental variable with Path variable data under user variables for <Username>
      • Edit Path Variable under User variables for <Username Section>
      • Append this value to other data.
        • ;%SONAR_RUNNER_HOME%\bin
  • Test Sonar Runner
    • Close all Command Prompt Windows
    • Open New Command Prompt Window
    • Run "sonar-runner.bat -h" command.
    • You should be able to see below data if setup is successful. 

Analyze A Project with SonarQube Runner:
  • Open your project root folder.
  • Create a configuration file with the name
  • file should contain values representing project name, unique key, what files should test, what files should exclude etc.
  • Example file.
  • Run Sonar on Project
    • Open Command Prompt
    • Move to Project Root Folder.
    • Run "sonar-runner" command.
  • Now go to http://localhost:9000/ URL.
  • Click on Projects link from Navigation Menu.
  • There you can see your Project Name after tests.
  • You can see overall status of project. Either pass or Fail beside to Project Name.

  • Click on that project name link and see fill set of test results as per files.
Note: Whenever you want to execute Sonar Tests, make sure,
  • Mysql is up and Running.
  • Sonar Server is up and Running
    • StartSonar.bat
In case of any issues with Sonar Sever, you can find logs in LOGS folder.
Sonar.log & web.log helps you alot in this process.

No comments:

Post a Comment

Thank you so much for providing your valuable feedback. I will will look into them and update my skills & technologies accordingly.