SonarQube is an open platform to manage code quality. We are going install sonarqube-5.6 and sonar-scanner-2.6 on Ubuntu 14.04.
Prerequisites
Java : Oracle JRE 8 or OpenJDK 8
MySQL-5.6 or later version
install OpenJDK 8
sudo apt-get update
sudo apt-get install openjdk-8-jdk
Install MySQL Server
sudo apt-get install mysql-server-5.6
Create the MySQL database for sonar
mysql -u root -p
CREATE DATABASE sonardb;
CREATE USER ‘sonar’@’localhost’ IDENTIFIED BY ‘sonarpassword’;
GRANT ALL PRIVILEGES ON sonardb.* TO ‘sonar’@’localhost’;
Download SonarQube and Sonarscanner
cd /opt
wget https://sonarsource.bintray.com/Distribution/sonarqube/sonarqube-5.6.zip
unzip sonarqube-5.6.zip
wget https://sonarsource.bintray.com/Distribution/sonar-scanner-cli/sonar-scanner-2.6.1.zip
unzip sonar-scanner-2.6.1.zip
Setting the access to the Database for Sonar
Edit /opt/sonarqube/conf/sonar.properties and uncommet and update DB name and password,
sonar.jdbc.username=sonardb
sonar.jdbc.password=sonarpassword
Uncomment the below line which is under MySQL 5.6 section,
sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance
Start sonar by executing the below command,
/opt/sonarqube/bin/linux-x86-64/sonar.sh start
Now, you can browser sonar in your browser http://your_ip:9000
Edit /opt/sonar-scanner/conf/sonar-scanner.properties and uncomment the below line
sonar.host.url=http://localhost:9000
create a sonar-project.properties file in your codes root directory with the below content,
sonar.projectKey=demo
sonar.projectName=demo
sonar.projectVersion=1.0.0
sonar.sources=app
sonar.language=js
sonar.dynamicAnalysis=reuseReports
Now we are ready to run sonar-scanner, go to your codes root directory and then run
/opt/sonar-scanner/bin/sonar-scanner
Once the sonar-scanner completed, you can see the report details in sonar dashboard http://your_ip:9000