简体   繁体   English

在 Jenkinsfile 中为 SonarQube 分析选择质量门

[英]Selecting Quality Gate for SonarQube Analysis in Jenkinsfile

I have a Jenkinsfile that, among other things, performs SonarQube analysis on my build and passes it through 'Quality Gate' stage.我有一个 Jenkinsfile,除其他外,它对我的​​构建执行 SonarQube 分析并通过“质量门”阶段。 The analysis is placed on the SonarQube server where I can see all the details.分析放置在 SonarQube 服务器上,我可以在其中查看所有详细信息。 The relevant pieces of code for the analysis and Quality gate are below (not mine, it is from 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).我已经查看了“ceTaskUrl”链接,该链接可以在 report-task.txt 文件中找到,但并没有深入研究(没有我可以看到和使用的变量来选择质量门)。

I also found this Jenkinsfile .我也找到了这个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.值得一提的是,我在我使用的 SonarQube 服务器上没有管理员权限。 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.您可以使用 WebAPI 执行此操作,但为此您需要Administer Quality Gate权限。

Please find more details here in this answer.请在此答案中找到更多详细信息。

How to assign Quality Gate dynamically to project from the script [SonarQube 6.5]? 如何从脚本 [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.或者,如果您没有获得适当的许可,那么另一种方法是使用 sonarqube UI,您可以在其中指定应将哪个 Quality Gate 用于哪个项目。

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

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