简体   繁体   English

Jenkins插件“ Sonarqube扫描仪”中所有可能返回的值是什么

[英]What are all possible returned value in Jenkins plugin “Sonarqube scanner”

I have a Jenkins pipeline job which build my application, make a Sonar analysis and then is the quality gate passed I deploy in ou Nexus with mvn deploy . 我有一个Jenkins管道作业,可构建我的应用程序,进行声纳分析,然后通过mvn deploy在ou Nexus中部署,通过了质量门。

The initial setup was to publish only in case of success (taken from the official doc ): 初始设置仅在成功的情况下发布(摘自官方文档 ):

stage("Quality Gate"){
      timeout(time: 1, unit: 'HOURS') {
          def qg = waitForQualityGate()
          if (qg.status != 'OK') {
              error "Pipeline aborted due to quality gate failure: ${qg.status}"
          }
      }
    }

and now we want to change a bit the logic gate in Jenkins and we would like to publish in case there no error (but eg Warning is acceptable). 现在我们想在Jenkins中更改一些逻辑门,并且我们希望在没有错误的情况下进行发布(但可以接受警告)。

For that I changed the Jenkins satge to: 为此,我将Jenkins座标更改为:

stage("Quality Gate"){
  timeout(time: 1, unit: 'HOURS') {
      def qg = waitForQualityGate()
      if (qg.status == 'Error') {
          error "Pipeline aborted due to quality gate failure: ${qg.status}"
      }
  }
}

stage('Deploy to Nexus') {
    sh "mvn deploy -DskipTests"
}

but now, it does not seems to work properly: my project is always pushed to Nexus even the Quality gate is in Error in SonarQube. 但是现在,它似乎无法正常运行:即使SonarQube中的Quality(质量)门出现错误,我的项目也总是被推送到Nexus。

I have a possible workaround by changing the condition: 我可以通过更改条件来解决此问题:

qg.status != 'OK' || qg.status != 'Warning' 

Anyone knows what is the exact value for the error status (and possibly other values)? 任何人都知道错误状态的确切值是多少(可能还有其他值)?

The documentation seems incomplete and there is no other way than guessing the correct return value. 该文档似乎不完整,除了猜测正确的返回值外,没有其他方法。

For preventing such issue I suggest to test without exact case like this: 为了防止出现此类问题,我建议在没有这种确切情况的情况下进行测试:

if ('error'.equalsIgnoreCase(qg.status) ) {
    error "Pipeline aborted due to quality gate failure: ${qg.status}"
} 

When using such condition my script is working fine, then it seems the value returned is in all capital case: 'ERROR'. 使用这种条件时,我的脚本可以正常工作,然后似乎返回的值在所有大写情况下均为“ ERROR”。

It's configurable via Webhooks in SonarQube Administration setup: https://docs.sonarqube.org/display/SONAR/Webhooks 可通过SonarQube管理设置中的Webhooks对其进行配置: https ://docs.sonarqube.org/display/SONAR/Webhooks

So, the method returns whatever you have configured for all Gateway Rules for OK or failure. 因此,该方法将返回您为所有“网关规则”配置为“正常”或失败的所有内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM