在Jenkins声明式管道中使用waitForQualityGate [英] Using waitForQualityGate in a Jenkins declarative pipeline

查看:1769
本文介绍了在Jenkins声明式管道中使用waitForQualityGate的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Jenkins 2.50中声明性管道中的以下SonarQube(6.3)分析阶段由于控制台日志中的此错误而失败: http ://pastebin.com/t2ja23vC .更具体地说:

The following SonarQube (6.3) analysis stage in a declarative pipeline in Jenkins 2.50 is failing with this error in the console log: http://pastebin.com/t2ja23vC. More specifically:

此作业(SonarGate)中定义的SonarQube安装与任何已配置的安装都不匹配.可以配置的安装数量:1.

SonarQube installation defined in this job (SonarGate) does not match any configured installation. Number of installations that can be configured: 1.

更新:在Jenkins设置中将"SonarQube"更改为"SonarGate"之后(在SonarQube服务器下,因此它将与Jenkinsfile匹配),我得到了另一个错误:

Update: after changing "SonarQube" to "SonarGate" in the Jenkins settings (under SonarQube servers, so it'll match the Jenkinsfile), I get a different error: http://pastebin.com/HZZ6fY6V

java.lang.IllegalStateException:无法获取SonarQube任务ID和/或服务器名称.请使用"withSonarQubeEnv"包装器进行分析.

java.lang.IllegalStateException: Unable to get SonarQube task id and/or server name. Please use the 'withSonarQubeEnv' wrapper to run your analysis.


该阶段是SonarQube文档中示例的修改:

我还用URL http://****/sonarqube-webhook/创建了一个Webhook sonarqube-webhook.是这样还是http://****/sonarqube/sonarqube-webhook?要访问服务器仪表板,请使用http://****/sonarqube.

I also created a webhook, sonarqube-webhook, with the URL http://****/sonarqube-webhook/. Should it be like that, or http://****/sonarqube/sonarqube-webhook? To access the server dashboard I use http://****/sonarqube.

在SonarQube的质量门"部分中,我创建了一个新的质量门:

In SonarQube's Quality Gates section I created a new quality gate:

我不确定SonarGate中的设置是否正确.我确实使用jenkins-mocha生成了一个lcov.info文件,该文件在Sonar中用于生成覆盖率数据.

I am not sure if the setting in SonarGate is correct. I do use jenkins-mocha to generate an lcov.info file that is used in Sonar to generate the coverage data.

也许质量门设置是错误的设置?最终结果是,如果未达到覆盖率%,将无法在詹金斯工作.

Perhaps the quality gate setting is the wrong setting to do? The end result is to fail the job in Jenkins if coverage % is not met.

最后,我不确定是否完全需要Jenkins系统配置中的以下配置:

Finally, I am not sure if the following configurations in the Jenkins system configuration are at all required:

还有

(这是9000而不是900 ...在屏幕截图中剪切了文本)

(It's 9000 not 900... cut text in the screen shot)

推荐答案

在使用Jenkins从站执行作业时,这是Jenkins的SonarQube扫描仪中的一个错误(如果作业在主服务器上运行,则为' d工作).您可以在此处了解更多信息: https://jira.sonarsource.com/browse/SONARJNKNS-282

This was discovered to be a bug in the SonarQube scanner for Jenkins, when using a Jenkins slave for jobs (if the job is run on the master, it'd work). You can read more here: https://jira.sonarsource.com/browse/SONARJNKNS-282

我已经使用扫描仪插件v2.61的测试版本对此进行了测试,并发现它可以正常工作. 解决方案是在发行时升级到v2.61.

I have tested this using a test build of v2.61 of the scanner plug-in and found it working. The solution is to upgrade to v2.61 when released.

此阶段将起作用:

stage ("SonarQube analysis") {
   steps {
      withSonarQubeEnv('SonarQube') {
         sh "../../../sonar-scanner-2.9.0.670/bin/sonar-scanner"   
      }

      def qualitygate = waitForQualityGate()
      if (qualitygate.status != "OK") {
         error "Pipeline aborted due to quality gate coverage failure: ${qualitygate.status}"
      }
   }
}

这篇关于在Jenkins声明式管道中使用waitForQualityGate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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