sonar.Qualitygate is Deprecated in Sonar Qube 5.3. What is the alternative?

后端 未结 3 767
日久生厌
日久生厌 2021-01-19 04:09

Context: In Sonar Qube, there exists a custom Quality Gate which is called say abcd. This is NOT the default quality gate. And in Jenkins, I had configured this

3条回答
  •  北海茫月
    2021-01-19 04:56

    Using approach, suggested by A_Di-Matteo , I faced an issue: when trying to select a gate for brand new feature branch, Sonar throw an error saying that project does not exist. So one can assign a gate only after project has been created. In this case, i use a hack: manually create a project using Sonar Web API just before assigning a gate, and only then performing mvn sonar:sonar step. Here is creation of dummy new project:

    def createNewProject(def config, def branch) {
        String projectName = new XmlSlurper().parseText(readFile('pom.xml')).name as String
        def url = "${config.sonarHost}/api/projects/create"
        sh "curl -u ${config.sonarToken}: ${url} -d 'name=${projectName}&project=${projectKey()}&branch=${branch}'"
    }
    

    Next step is assigning a Gate for this dummy project:

    def setSonarQualityGate(def config, def projectFullName, def gateId) {
        def url = "${config.sonarHost}/api/qualitygates/select"
        sh "curl -u ${config.sonarToken}: ${url} -d 'gateId=${gateId}&projectKey=${projectFullName}'"
    }
    

    And only after that I execute analysis itself:

    def runSonarAnalysis(def config, def branch) {
        echo "Run Sonar analysis"
        sh "mvn sonar:sonar -Dsonar.host.url=${config.sonarHost} -Dsonar.branch=${branch}"
    }
    

提交回复
热议问题