为什么SONAR在waitForQualityGate()上失败并出现错误401? [英] Why SONAR fails at waitForQualityGate() with error 401?

查看:2052
本文介绍了为什么SONAR在waitForQualityGate()上失败并出现错误401?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用管道代码,

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}"
        }
    }

在第一个mvn部分上逐渐进展,并在waitforqualitygate()操作上中断:

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

该链接是可单击的,并导致填充的json结构.

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

为什么构建失败?在声纳中似乎已正确设置了Webhook,并且其他声纳项目正在正常运行,在jenkis中的webhook也似乎处于活动状态.

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.

推荐答案

类似于官方中所述SonarQube Scanner for Jenkins的文档,您必须在withSonarQubeEnv之外使用waitForQualityGate():

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}"
    }
  }
}

这篇关于为什么SONAR在waitForQualityGate()上失败并出现错误401?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆