SonarQube is one of the popular static code analysis tools. SonarQube is open-source, java based tool It also needs database as well
- Database can be MySQL, Oracle or PostgreSQL. We will use PostgreSQL as it is open source as well.
Please find steps for installing SonarQube 7.7 on Ubuntu 18.0.4. Make sure port 9000 is opened in security group(firewall rule).
Please find steps for installing SonarQube 7.7 on Ubuntu 18.0.4. Make sure port 9000 is opened in security group(firewall rule).
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/ repos/apt/ `lsb_release -cs`-pgdg main" >> /etc/apt/sources.list.d/pgdg.list'
sudo wget -q https://www.postgresql.org/med ia/keys/ACCC4CF8.asc -O - | sudo apt-key add -
sudo apt-get -y install postgresql postgresql-contrib
Ignore the message in red color below:
Start PostGresSQL
sudo systemctl start postgresql
sudo systemctl enable postgresql
Login as postgres user
sudo su - postgres
Now create a sonar user below
createuser sonar
3. Now install SonarQube Web App
sudo wget https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-7.7.zip
sudo apt-get -y install unzip
sudo unzip sonarqube-7.7.zip -d /opt
sudo mv /opt/sonarqube-7.7 /opt/sonarqube -v
Create Group and User:
sudo groupadd sonarGroup
Now add the user with directory access
sudo useradd -c "user to run SonarQube" -d /opt/sonarqube -g sonarGroup sonar
sudo chown sonar:sonarGroup /opt/sonarqube -R
Modify sonar.properties file
sudo vi /opt/sonarqube/conf/sonar.prop erties
uncomment the below lines by removing # and add values highlighted yellow
sonar.jdbc.username=sonar
sonar.jdbc.password=password
Next, add the below line:
sonar.jdbc.url=jdbc:postgresql ://localhost/sonarqube
Press escape, and enter :wq! to come out of the above screen.
Edit the sonar script file and set RUN_AS_USER
sudo vi /opt/sonarqube/bin/linux-x86-64/sonar.sh
(Scroll down by using down arrow button)
#enable the below line by removing #
RUN_AS_USER=sonar
Create Sonar as a service
Execute the below command:
sudo vi /etc/systemd/system/sonar.serv ice
add the below code in green color, please press insert button before you copy and paste.
[Unit]
Description=SonarQube service
After=syslog.target network.target
[Service]
Type=forking
ExecStart=/opt/sonarqube/bin/l inux-x86-64/sonar.sh start
ExecStop=/opt/sonarqube/bin/li nux-x86-64/sonar.sh stop
User=sonar
Group=sonarGroup
Restart=always
Description=SonarQube service
After=syslog.target network.target
[Service]
Type=forking
ExecStart=/opt/sonarqube/bin/l
ExecStop=/opt/sonarqube/bin/li
User=sonar
Group=sonarGroup
Restart=always
[Install]
WantedBy=multi-user.target
WantedBy=multi-user.target
# once you add press :wq! to come out of the above editor
sudo systemctl start sonar
sudo systemctl enable sonar
sudo systemctl status sonar
type q now to come out of this mode.
Now execute the below command to see if Sonarqube is up and running. This may take a few minutes.
Check Sonar logs by executing tail command:
tail -f /opt/sonarqube/logs/sonar.log
Make sure you get the below message that says sonarqube is up..
Now access SonarQube UI by going to browser and enter public dns name with port 9000
Now to go to browser --> http://your_SonarQube_publicdns_name:9000 /
Login as admin/admin
Please follow steps for integrating SonarQube with Jenkins
https://www.coachdevops.com/2020/04/how-to-integrate-sonarqube-with-jenkins.html
Please watch the above steps as a demo in YouTube as well:
https://www.coachdevops.com/2020/04/how-to-integrate-sonarqube-with-jenkins.html
Please watch the above steps as a demo in YouTube as well:
No comments:
Post a Comment