git 如何让SonarQube检测非主分支?

dsekswqp  于 2023-03-11  发布在  Git
关注(0)|答案(1)|浏览(193)

我查阅了以下文档:https://docs.sonarqube.org/latest/branches/overview/,但我无法让SonarQube检测master分支以外的其他分支(我使用的是开发者版本)。我已经将以下参数作为变量传递给pom.xml属性:<sonar.branch.name>${git.branch}</sonar.branch.name> .

bkhjykvo

bkhjykvo1#

最后,我发现这是Jenkins管道造成的问题。最后,我不得不修改Jenkins文件中的步骤,以便SonarQube检测到我的分支。

steps {
    script {
        slackSend message:"Starting Project Name Full Test Build Version ${VERSION} - ${env.JOB_NAME} ${env.BUILD_NUMBER} (<${env.BUILD_URL}|Open>)", baseUrl: "https://projectname.slack.com/services/hooks/jenkins-ci/", token: "token"
    }   
    echo 'Starting Project Name Full Test Build and Sonar Analysis'
    withSonarQubeEnv('Sonar') {
        sh 'mvn clean verify -P full-test sonar:sonar -Dsonar.branch.name=$BRANCH_NAME -e --settings ${SETTINGS}'
    }
    script {
        sleep(20)
        def qualitygate = waitForQualityGate()
        if (qualitygate.status != "OK") {
                error "Project Name Full Test Build FAILED due to quality gate failure: ${qualitygate.status}"
        }
    }
    script {
        if ($BRANCH_NAME == "master") {
            echo 'Starting SNAPSHOT artifact deploy'
            sh 'mvn clean deploy -DskipTests -P dist --settings ${SETTINGS}'
        }
    }

相关问题