1.配置jenkins的sonarqube和token
2.增加代码检查的pipeline的质量门禁语法
pipeline {
agent any
stages{
stage('拉取git代码'){
steps{
checkout([$class: 'GitSCM',
branches: [[name: '*/dev']],
userRemoteConfigs: [[credentialsId: 'c440c10e7a2d4d41ba95f6ccea43e9df', url: ' ']]])
}
}
stage('代码检查'){
agent {
docker {
image 'boatswain.registry.si-tech.com.cn:30100/devops/sonar-scanner:v2'
args '-v /user/share/sonar-scanner-3.1.0.1141-linux'
reuseNode true
}
}
steps{
withSonarQubeEnv('SonarQube') {
sh "sonar-scanner -Dsonar.projectKey=D87F9380BFDC4AB21DB0E86BC4FFC3A4 -Dsonar.language=java -Dsonar.sources=. -Dsonar.projectBaseDir=. -Dsonar.java.binaries=."
}
script {
timeout(1) {
def qg = waitForQualityGate('SonarQube')
if (qg.status != 'OK') {
error "未通过Sonarqube的代码质量阈检查,请及时修改!failure: ${qg.status}"
}
}
}
}
}
}
}
3.配置sonarqube的webhook