就像SonarQube Scanner for
Jenkins的官方文档中所述,您必须
waitForQualityGate()在以下范围之外使用
withSonarQubeEnv:
node { stage('SCM') { git 'https://github.com/foo/bar.git' } stage('SonarQube analysis') { withSonarQubeEnv('My SonarQube Server') { sh 'mvn clean package sonar:sonar' } // SonarQube taskId is automatically attached to the pipeline context }}// No need to occupy a nodestage("Quality Gate"){ timeout(time: 1, unit: 'HOURS') { // Just in case something goes wrong, pipeline will be killed after a timeout def qg = waitForQualityGate() // Reuse taskId previously collected by withSonarQubeEnv if (qg.status != 'OK') { error "Pipeline aborted due to quality gate failure: ${qg.status}" } }}


