在Jenkinsfile中为SonarQube分析选择质量门 [英] Selecting Quality Gate for SonarQube Analysis in Jenkinsfile

查看:197
本文介绍了在Jenkinsfile中为SonarQube分析选择质量门的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Jenkinsfile,除其他外,它对我的​​构建执行SonarQube分析,并将其传递到"Quality Gate"阶段.分析放在SonarQube服务器上,在这里我可以查看所有详细信息.用于分析和质量门的相关代码如下(不是我的,它来自文档):

stage('SonarCloud') {
      steps {
        withSonarQubeEnv('SonarQube') {

            sh 'mvn clean package sonar:sonar '

        }
      }
    }

stage("Quality Gate") {
      steps {
        timeout(time: 15, unit: 'MINUTES') { // If analysis takes longer than indicated time, then build will be aborted
            waitForQualityGate abortPipeline: true
            script{
                def qg = waitForQualityGate() // Waiting for analysis to be completed
                if(qg.status != 'OK'){ // If quality gate was not met, then present error
                    error "Pipeline aborted due to quality gate failure: ${qg.status}"
                }
            }
        }
      }
    }

当前,一旦分析完成并放在服务器上,它将使用服务器的默认质量门.我想知道在进入质量门"阶段之前是否可以指定要在分析中使用的质量门? (我设置了另一个质量门,使用了不同的接受标准,我想将其用于质量门"阶段.)

无法更改默认质量门,因为其他人正在使用它(因此,为什么要设置自己的质量门).

我已经查看了"ceTaskUrl"链接,该链接可以在report-task.txt文件中找到,但并没有走得很远(我无法看到并使用任何变量来选择质量门). /p>

我还找到了 Jenkinsfile .我尝试使用它的一些代码,并在其上附加更多谷歌搜索功能,希望访问和更改质量门,但也没有走得太远.

值得一提的是,我在使用的SonarQube服务器上没有管理员权限.但是,我可以要求根据需要配置新的质量门.

解决方案

您可以使用WebAPI进行此操作,但为此需要管理质量门权限.

请在此答案中找到更多详细信息.

documentation):

stage('SonarCloud') {
      steps {
        withSonarQubeEnv('SonarQube') {

            sh 'mvn clean package sonar:sonar '

        }
      }
    }

stage("Quality Gate") {
      steps {
        timeout(time: 15, unit: 'MINUTES') { // If analysis takes longer than indicated time, then build will be aborted
            waitForQualityGate abortPipeline: true
            script{
                def qg = waitForQualityGate() // Waiting for analysis to be completed
                if(qg.status != 'OK'){ // If quality gate was not met, then present error
                    error "Pipeline aborted due to quality gate failure: ${qg.status}"
                }
            }
        }
      }
    }

Currently, once the analysis is completed and placed on the server, it uses server's default quality gate. I wonder if I can specify which quality gate to use with my analysis, before proceeding to 'Quality gate' stage? (I have another quality gate set up, with different acceptance criteria, that I would like to use for 'Quality Gate' stage).

Altering the default quality gate cannot be done because other people are using it (hence why I have my own quality gate set up).

I have looked into 'ceTaskUrl' link, that can be found in report-task.txt file, but didn't get far with it (no variable that I can see, and use, to select quality gate).

I also found this Jenkinsfile. I tried to use some of its code, with additional googling on top of it, in hopes to access and alter quality gate, but also didn't get far with it.

It is worth mentioning that I do not have admin privileges at the SonarQube server I am using. However, I can request for a new quality gate to be configured as required, in case it is needed.

解决方案

You can do so using the WebAPI but for that you need Administer Quality Gate permission.

Please find more details here in this answer.

How to assign Quality Gate dynamically to project from the script [SonarQube 6.5]?

Or in case you don’t get the proper permission, then the alternate way is to use sonarqube UI, where you can specify which Quality Gate should be used for which project.

这篇关于在Jenkinsfile中为SonarQube分析选择质量门的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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