Why SONAR fails at waitForQualityGate() with error 401?

房东的猫 提交于 2019-12-11 08:39:59

问题


Using pipeline code,

stage ('SonarQube') {
    withSonarQubeEnv {
        dir ('mydir/') {
            sh "'${mvnHome}/bin/mvn' sonar:sonar -Dsonar.login=something -Dsonar.projectKey=someproj -Dsonar.projectName=somename"
        }
    }
    timeout(time: 15, unit: 'MINUTES') {
        def qg = waitForQualityGate()
        if (qg.status != 'OK') {
            error "Pipeline aborted due to quality gate failure: ${qg.status}"
        }
    }

Which progresses crrectly over the first mvn section and breaks on waitforqualitygate() operation:

org.sonarqube.ws.client.HttpException: Error 401 on http://mysonarserver/sonar/api/ce/task?id=somecode

the link is clickable and leads to a filled json structure.

Why the build fails? Webhook seems to be set properly in sonar, and other sonar projects are working correctly, webhook in jenkis also seems to be active.


回答1:


Like described in the official documentation of the SonarQube Scanner for Jenkins, you must use waitForQualityGate() outside of 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 node
stage("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}"
    }
  }
}


来源:https://stackoverflow.com/questions/43588403/why-sonar-fails-at-waitforqualitygate-with-error-401

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!