$ sudo apt update
$ sudo apt -y install apt-transport-https ca-certificates curl gnupg-agent software-properties-common
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
$ wget https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-9.8.0.63668.zip
$ unzip sonarqube-9.8.0.63668.zip
$ sudo groupadd sonar
$ sudo useradd -c "SonarQube - User" -d /home/shlee/sonarqube/ -g sonar sonar
# $ sudo chown -R sonar:sonar /home/shlee/sonarqube/
$ sudo chown -R shlee:shlee /home/shlee/sonarqube/
$ /home/shlee/sonarqube/bin/linux-x86-64/sonar.sh start
$ /home/shlee/sonarqube/bin/linux-x86-64/sonar.sh stop
$ curl localhost:9000 [admin/admin and change password]
[SonarQube Setup in gitlab / SonarQube]
1) create gitlab Impersonation Token in Gitlab
2) create gitlab project and insert gitlab Token in sonarqube
3) create credential for "admin" account in sonarqube
and copy credential, paste to jenkins new credentials
[SonarQube Setup In jenkins]
Install GitLab plugin for Jenkins - version 1.5.13 or later
Install SonarQube Scanner plugin for Jenkins - version 2.11 or later
setting for integrating cicd
setting for sonarqube server
[Jenkinsfile]
withSonarQubeEnv('sonarqube_rookie01') {
sh "mvn clean verify sonar:sonar -Dsonar.projectKey=springboot_springboot-cicd_AYUplgxydso4nsDrpk6X"
}
sonarqube_rookie01 <- ID for sonarQube Server Setting
springboot_springboot-cicd_AYUplgxydso4nsDrpk6X <-- project key in sonarqube
-----
(1) Docker Push in Jenkinsfile
docker.withRegistry('<Docker Registry URL>', '<Credential defined in Jenkins Credentials>') {
dockerImage.push('<Tag>')
}
ex>
docker.withRegistry('http://localhost:7890/repository/docker-local-registry/', 'docker_credential') {
dockerImage.push('latest')
}
(2) Integrate Sonar with Jenkins
withSonarQubeEnv('<Name of Jenkins SonarQube Server Settings>') {
sh "mvn clean verify <Goal for SonarQube (default : 'sonar:sonar' )> -Dsonar.projectKey=<ProjectKey generated by SonarQube Server>"
}