One 、 install SonarScanner
Download address :https://docs.sonarqube.org/latest/analysis/scan/sonarscanner/
[[email protected] ~]# unzip sonar-scanner-cli-4.6.2.2472-linux.zip -d /opt/SonarScanner
[[email protected] ~]# vi /etc/profile
#SonarScanner
export Sonar_Home=/opt/SonarScanner/
export PATH=$Sonar_Home/bin:$PATH
[[email protected] ~]# source /etc/profile
Two 、 stay Jenkins Install in Sonar plug-in unit
(1) Search for SonarQube Scanner, Find the plug-in , install

(2) stay Jenkins Middle configuration SonarQube

3、 ... and 、 Create pipeline tasks
(1) New assembly line

(2) To write Pipeline Script
pipeline{
agent { node { label "build"}}
stages{
stage("CheckOut"){
steps{
script{
tools.PrintMes(" Pull the code ","green")
checkout([$class: 'GitSCM', branches: [[name: '*/master']], extensions: [],\
userRemoteConfigs: [[credentialsId: 'gitlab', url: 'https://gitlab.com/Bypass007/simple-java-maven-app.git']]])
}
}
}
stage("Build"){
steps{
script{
tools.PrintMes(" Perform packaging ","green")
mvnhome = tool 'M2'
sh "${mvnhome}/bin/mvn ${buildShell}"
}
}
}
stage("CodeScan"){
steps{
script{
tools.PrintMes(" Code scanning ","green")
sonar.SonarScan("${JOB_NAME}","${JOB_NAME}","src")
}
}
}
}
}
(3) Successfully build task , Passed code scanning .
Reference link :https://www.cnblogs.com/cjsblog/p/10740840.html
https://github.com/zeyangli/jenkinslibrary/blob/master/jenkinsfiles/ci.jenkinsfile