Can't call waitForQualityGate with (npm-based) sonar-scanner; leads to "Unable to get SonarQube task id and/or server name."

696 views
Skip to first unread message

wansart....@gmail.com

unread,
Dec 1, 2017, 12:18:38 PM12/1/17
to SonarQube
Hello,

I have two projects: one uses Angular the other Java/Maven. On the maven part the sonarqube analysis as well as the quality gate code works fine. Both use a Jenkinsfile for the pipeline. To be specific, this is working:
stage("SonarQube analysis for ${module}") {
withSonarQubeEnv('My SonarQube') {
def commonGoal = "-Dsonar.projectName=${module}_${env.BRANCH_NAME} -Dsonar.projectKey=${Config.groupId}:${module}_${env.BRANCH_NAME} -Dsonar.host.url=${Config.sonarUrl}"
mvn(module, "sonar:sonar ${commonGoal} -Dsonar.analysis.mode=issues -Dsonar.gitlab.commit_sha=${Config.scmVars.GIT_COMMIT} -Dsonar.gitlab.ref_name=${Config.scmVars.GIT_BRANCH} -Dsonar.gitlab.project_id=${Config.gitlabProjectId}")
}
}
stage("Quality Gate") {
timeout(time: 1, unit: 'HOURS') {
def qg = waitForQualityGate()
if (qg.status != 'OK') {
error "Pipeline aborted due to quality gate failure: ${qg.status}"
}
}
}


And I got almost the same just with the npm based sonar-scanner which fails when the waitForQualityGate() is called:

withSonarQubeEnv('My SonarQube') {
def sonarScanner = "./node_modules/sonarqube-scanner/dist/bin/sonar-scanner -Dsonar.projectName=frontend_${env.BRANCH_NAME} -Dsonar.projectKey=${Config.groupId}:frontend_${env.BRANCH_NAME}"
sh 'npm install -D sonarqube-scanner'
sh "${sonarScanner}"
sh "${sonarScanner} -Dsonar.analysis.mode=issues -Dsonar.gitlab.commit_sha=${Config.scmVars.GIT_COMMIT} -Dsonar.gitlab.ref_name=${Config.scmVars.GIT_BRANCH} -Dsonar.gitlab.project_id=${Config.gitlabProjectId}"
}

def qg = waitForQualityGate()
if (qg.status != 'OK') {
error "Pipeline aborted due to quality gate failure: ${qg.status}"
}


The error message I get in Jenkins is:
java.lang.IllegalStateException: Unable to get SonarQube task id and/or server name. Please use the 'withSonarQubeEnv' wrapper to run your analysis.
	at org.sonarsource.scanner.jenkins.pipeline.WaitForQualityGateStep$Execution.processStepParameters(WaitForQualityGateStep.java:125)
	at org.sonarsource.scanner.jenkins.pipeline.WaitForQualityGateStep$Execution.start(WaitForQualityGateStep.java:107)
        ... many more ...


I tried different ways but none of them worked so far. I've read that this was bugged but fixed with version 2.61; mine is newer. The only possible solution I see so far is to use the maven sonar plugin, but for that I need to add an almost empty pom.xml. So... Does anybody know what I can try to solve this the "npm way"?

Thanks and best regards,
Christian

wansart....@gmail.com

unread,
Dec 4, 2017, 2:19:00 AM12/4/17
to SonarQube
It seems that even the sonar-maven-plugin causes the same error for this project. I guess the issue is somewhere else. But both projects are multibranch pipeline projects. Hmm...

Any ideas?

G. Ann Campbell

unread,
Dec 6, 2017, 3:08:16 PM12/6/17
to SonarQube
Hi Christian,

If either job can fail intermittently, then I'm wondering if an hour timeout is long enough. Have you verified that the analysis reports from the timed out jobs actually are being processed within the hour?


Ann

wansart....@gmail.com

unread,
Dec 7, 2017, 2:38:36 AM12/7/17
to SonarQube
Hey,

thanks for you answer. I managed to fix it. I am not 100 % sure, but I think I messed up somewhere the braces. I also forgot to add the webhook in SonarQube. 

Best regards,
Christian
Reply all
Reply to author
Forward
0 new messages