jenkins - WaitForQualityGate 退出并在 Jenkins slave 上出现错误

标签 jenkins sonarqube jenkins-pipeline sonarqube-scan

我正在运行一个 Jenkins 实例,它有 1 个主服务器/1 个从服务器,连接到一个 Sonarqube 实例。我正在使用管道作业,它工作正常,除了在“WaitForQualityGate”阶段不起作用的 jenkins slave 上。它在 master 上运行良好。

我的工作因这个错误而退出:

Java.lang.IllegalStateException: Unable to get SonarQube task id and/or server name. Please use the 'withSonarQubeEnv' wrapper to run your analysis.

即使之前调用了“withSonarQubeEnv”阶段。

我的配置是:

  • Jenkins 作业有一个“管道脚本”检查我的源代码 + 管道脚本
  • 隐式加载共享库
  • withSonarQubeEnv 在“testCover”期间调用,waitForQualityGate 在“testQualityGate”期间调用

Jenkins 作业流水线脚本:

node(){
    checkout changelog: false, poll: false, scm: [$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'jenkinsfile'], [$class: 'IgnoreNotifyCommit'], [$class: 'WipeWorkspace']], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'credential', url: 'https://pipeline.git']]]
    checkout changelog: true, scm: [$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'src'], [$class: 'WipeWorkspace']], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'credential', url: 'https://sourcecode.git']]]
    load 'jenkinsfile/Jenkinsfile'
}()

共享库(testCover):

echo "Testing the coverage of the application"
withSonarQubeEnv('sonarqube') {
    withCredentials([string(credentialsId: 'sonarqube-token', variable: 'sonarqube_token')]) {
        def scannerCmd = "sonar-scanner -e";
        scannerCmd += " -Dhttps.proxyHost=proxy.com";
        scannerCmd += " -Dhttps.proxyPort=8888";
        scannerCmd += " -Dhttp.proxyHost=proxy.com";
        scannerCmd += " -Dhttp.proxyPort=8888";
        scannerCmd += " -Dsonar.login=${env.sonarqube_token}";
        scannerCmd += " -Dsonar.password=";
        sh "${scannerCmd}"
    }
}

共享库(testQualityGate):

sleep 10
timeout(time: 3, unit: 'MINUTES') {
    def qg = waitForQualityGate()
    if (qg.status != 'OK') {
        error "Pipeline aborted due to quality gate failure: ${qg.status}"
    }
}

管道作业:

{->
    node {
        dir('src'){
            stage ('Init') {
                initLib('node7')
            }

            stage ('Build app') {
                withCredentials([[
                    $class: 'UsernamePasswordMultiBinding',
                    credentialsId: 'npm-server',
                    usernameVariable: 'REG',
                    passwordVariable: 'TOKEN'
                ]]) {
                    sh "echo '\n//${env.REG}/:_authToken=${env.TOKEN}' >> .npmrc"
                    buildApp()
                }
            }

            stage ('Test / Lint') {
                testApp()
            }

            stage ('Cover / static analysis') {
                testCover()
            }

            stage ('Quality Gate') {
                testQualityGate()
            }

            stage ('Flowdock notification') {
                notifyFlowdock()
            }
        }
    }
}

编辑:在深入调查之后,我发现问题可能来自对 node 语句的 2 次调用(我的管道脚本(作业)中有 1 次,我的管道文件中有 1 次)。不幸的是,这并没有解决我的问题 =/ 编辑 2:我检查了我的构建日志中是否存在“Working dir:”和“ANALYSIS SUCCESSFULL”行,因为 Sonar 插件使用这些行来查找“.sonar”文件夹的 URL + PATH(任务所在的位置) -report.txt 是),他们是!所以基本上,它在主节点上工作,但在从节点上不工作,即使它们都有相同的输出 =/

最佳答案

我正在回答我自己的问题,让您知道在 jenkins 的 Sonar 插件中发现了一个实际问题。这是补丁 https://repox.sonarsource.com/sonarsource-public-builds/org/jenkins-ci/plugins/sonar/2.6.1.1212/sonar-2.6.1.1212.hpi

感谢 google 组 (https://groups.google.com/forum/?utm_medium=email&utm_source=footer#!topic/sonarqube/z_K_wz_8Vw8) 中的所有人提供的帮助:)

关于jenkins - WaitForQualityGate 退出并在 Jenkins slave 上出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42898529/

相关文章:

maven - docker maven 镜像的 Jenkins 管道脚本退出状态 -1

java - 从 Jenkins 的邮件中发送 SonarQube 链接

visual-studio - 如何在 Microsoft Surface 上自动化非交互式测试

java - 打开 zip 文件时出错或缺少 : build/tmp/expandedArchives/org. jacoco.agent 的 JAR list

Jenkins 管道检查网站可用性问题

jenkins - 为什么 jenkins 源代码管理配置没有?

jenkins - 没有名为 SonarQube Scanner 2.8 的工具发现错误

java - 构建失败,出现异常 : Task '—' not found in root project

jenkins - 无法使用变量在 jenkins 管道中的字符串匹配后替换行

unit-testing - 使用 Groovy 模拟 Jenkins 管道