Selecting Quality Gate for SonarQube Analysis in Jenkinsfile

只愿长相守 提交于 2021-01-29 10:58:12

问题


I have a Jenkinsfile that, among other things, performs SonarQube analysis on my build and passes it through 'Quality Gate' stage. The analysis is placed on the SonarQube server where I can see all the details. 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).

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.


回答1:


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.



来源:https://stackoverflow.com/questions/64482367/selecting-quality-gate-for-sonarqube-analysis-in-jenkinsfile

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!