请参考链接:http://www.iotxing.com/2019/06/12/258/jenkins-pipeline-waitforqualitygate%E8%B6%85%E6%97%B6/
主要是因为sonaqube的一个小bug, 需要sleep 几秒
pipeline { agent any //任务集合,一个大的任务 stages { stage('代码获取') { steps { checkout([$class: 'GitSCM', branches: [[name: '${git_version}']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: '0f180207-47bf-20-a9-a20fd91f445f', url: 'git@gitlab.domain.com:xxx/monitor.git']]]) } } stage('代码质检') { steps { withSonarQubeEnv('SonarQube') { sh '/usr/local/sonar-scanner/bin/sonar-scanner -Dsonar.projectKey=html -Dsonar.projectName=${JOB_NAME} -Dsonar.sources=.' } script { timeout(1) { sleep(5) def qg = waitForQualityGate() if (qg.status != 'OK') { error "未通过SonarQube的代码检查,请及时修改! failure: ${qg.status}" } } } } } stage('代码构建') { steps { echo "build is ok" } } stage('代码部署') { steps { sh '/usr/local/shell/pipeline_deploy_html.sh' } } } post { failure { dingTalk accessToken: 'd631ae76dabd6fabba81b1fe4a7f3d2fe3a8da8636ba72554348efe1982a', imageUrl: '', jenkinsUrl: 'http://jenkins.domain.com:8080/', message: '代码部署失败', notifyPeople: 'phone' } success { dingTalk accessToken: 'd631ae76dabd6fabba81b1fe4a7f3d2fe3a8da8636ba725348ef71e1982a', imageUrl: '', jenkinsUrl: 'http://jenkins.domain.com:8080/', message: '代码部署成功', notifyPeople: 'phone' } } }