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