Reputation: 163
I'm running a Jenkins instance with 1 master / 1 slave, connected to a Sonarqube instance. I'm using pipeline jobs, and it works fine except on jenkins slave where the "WaitForQualityGate" stage doesn't work. It works fine on master.
My job exit with this error:
Java.lang.IllegalStateException: Unable to get SonarQube task id and/or server name. Please use the 'withSonarQubeEnv' wrapper to run your analysis.
Even if the stage "withSonarQubeEnv" is called before.
My configuration is:
Jenkins job pipeline script:
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'
}()
Shared library (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}"
}
}
Shared library (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}"
}
}
Pipeline job:
{->
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()
}
}
}
}
EDIT: After investigating deeper, i found out that the problem might come from the 2 calls to node
statement (1 in my pipeline script (job), 1 in my pipeline file). Unfortunately, that's not solving my issue =/
EDIT 2: I checked that the line "Working dir:" and "ANALYSIS SUCCESSFULL" are present in my build log, as Sonar plugin use those lines to find out the URL + the PATH for the ".sonar" folder (where the task-report.txt is), and they are ! So basically, it's working on Master node, but not on Slave, even if they both have the same output =/
Upvotes: 3
Views: 3864
Reputation: 163
I'm answering my own question to let you know that there was an actual issue that has been spotted in sonar plugin for jenkins. Here is the patch https://repox.sonarsource.com/sonarsource-public-builds/org/jenkins-ci/plugins/sonar/2.6.1.1212/sonar-2.6.1.1212.hpi
Thanks all the people in the google group (https://groups.google.com/forum/?utm_medium=email&utm_source=footer#!topic/sonarqube/z_K_wz_8Vw8) for the help provided : )
Upvotes: 2