我正在运行一个带有1个master / 1 slave的Jenkins实例,连接到Sonarqube实例。我正在使用管道作业,它工作正常,除了jenkins slave,其中“WaitForQualityGate”阶段不起作用。它在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作业管道脚本:
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是),他们是!所以基本上,它在主节点上工作,但在Slave上不工作,即使它们都具有相同的输出= /
答案 0 :(得分:2)
我回答了我自己的问题,让你知道在jenkins的声纳插件中发现了一个实际的问题。这是补丁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)提供的帮助:)