What is SonarQube
SonarQube formerly known as Sonar, is an open source tool suit to measure and analyze to quality of source code. It is written by Java but is able to analyze code in 20 different programming languages. With SonarQube, developers can easily to check to ensure quality, reliability and maintainability over life-span of the project.
In this part 3, we are going to install SonarQube with Docker. This is just for testing and demostrating.
Install docker
Remove old docker and docker components
sudo yum remove docker docker-common docker-selinux docker-engine
Install dependency
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
Add Third Party Docker Repo
I have a bad network connection with Docker Official Repo, so I choose the third party repo, which is faster than Docker’s one.
wget -O /etc/yum.repos.d/docker-ce.repo https://mirrors.huaweicloud.com/docker-ce/linux/centos/docker-ce.repo
For Docker Official Repo, Please use the following
sudo yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
update yum index and install docker
sudo yum makecache fast
sudo yum install docker-ce
enable and start docker
[root@jenkins ~]# systemctl enable docker
[root@jenkins ~]# systemctl start docker
Pull SonarQube image from docker
[root@jenkins ~]# docker pull sonarqube
I set recommend values for current session by using following commands as root on the host
sysctl -w vm.max_map_count=262144
sysctl -w fs.file-max=65536
ulimit -n 65536
ulimit -u 4096
Run SonarQube
[root@jenkins ~]# docker run -d --name sq -p 9000:9000 sonarqube
if SonarQube instance is killed by docker after a while, it is best to configure a timeout to stop the container with –stop-timeout
[root@jenkins ~]# docker run -d --stop-timeout 3600 sonarqube --name sq -p 9000:9000 sonarqube
After SonarQube installed, access http://192.168.1.19:9000/ to login and configure.
The default username and password is admin/admin
Once login, SonarQube will ask you to provide a token name and generate a token.
Keep this Token, we will add it into Jenkins crentials.
Integrate Sonar with Jenkins
Install SonarQube Plugins in Jenkins.
Navigate to Manage Jenkins->Manage Plugins
Configure SonarQube servers in Jenkins
Navigate to Manage Jenkins->Configure System->SonarQube servers,
Go to Manage Jenkins->Global Tool Configuration
Conclusion
In this post, we have learned to install SonarQube with Docker and configure Sonar settings in Jenkins. we have generated a Token of SonarQube that will be used to authorize to login SonarQube.