2017-04-24 214 views
1

使用管道代码,为什么SONAR在错误401时在waitForQualityGate()失败?

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符()crrectly进展操作:

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

链接是可以点击的,导致填充的JSON结构。

为什么构建失败? Webhook似乎在声呐中设置正确,其他声呐项目正常工作,在纯正的webhook似乎也很活跃。

回答

2

就像在official documentation of the 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 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}" 
    } 
    } 
} 
+0

对不起,我粘贴了错误的代码。它在withSonarQubeEnv之外 – koller23

+0

确定节点分配是问题 – koller23

+0

当将质量门步骤添加到JenkinsFile时,我得到完全相同的错误。 –

0

添加质量门一步JenkinsFile时,我恰好有同样的错误。 SonarQube版本是6.3,我使用DSL作为管线 舞台看起来像这样。

stage("SonarQube Quality Gate") { 
     steps { 
     script { 
     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}" 
      } 
      } 
      } 
     } 
     } 
+0

@Fabrice请指导 –

+1

您如何运行支票? 如果是从maven/gradle执行,即不是通过插件执行,那么“管理Jenkins” - >“配置系统” - >“Sonar Qube服务器” - >“服务器认证令牌”中的凭据有可能是不正确。 – ikolomiyets

+0

感谢上述纠正步骤解决401问题,但我的构建现在陷入了这条消息“SonarQube任务'XXXXXX'状态是'待办'”。 –

相关问题