Jenkins integrated sonarqube

  jenkins, sonar

Version information

  • jenkins:2.23.3

  • sonarqube:5.6.6

Maven acceleration

    <mirror>
        <id>nexus-aliyun</id>
        <mirrorOf>*</mirrorOf>
        <name>Nexus aliyun</name>
        <url>http://maven.aliyun.com/nexus/content/groups/public</url>
    </mirror> 

Reuse local maven warehouse

docker run -p 8080:8080 -p 50000:50000 \
-e JAVA_OPTS=-Duser.timezone=Asia/Shanghai \
-v /Users/xixicat/.m2/repository:/var/repository \
-v /Users/xixicat/jenkins:/var/jenkins_home \
jenkins

The time zone is set here by the way.

Run sonar

docker run -d --name sonarqube \
 -p 9000:9000 -p 9092:9092 \
  -e SONARQUBE_JDBC_USERNAME=sonar \
  -e SONARQUBE_JDBC_PASSWORD=sonar \
  sonarqube:lts-alpine

The default embedded database is used here.

Configure sonar

Set server address

configuration-general settings-Server base URL
insteadhttp://192.168.99.100:9000

Generate token

My Account -security-generate tokens

Jenkins set sonar

  • Plugin to install sonar
    SonarQube Scanner for Jenkins

  • System Management-System Settings -SonarQube servers
    Set ServerURL:http://192.168.99.100:9000

Set Server authentication token as the token generated in the previous step.
图片描述

  • System management -Global Tool Configuration
    Add SonarQube Scanner installation to report scan code to sonarqube server on command line.

图片描述

Configure job

图片描述

View sonar

After the job is built, there are links to jump to sonarqube.

图片描述

doc