I’m trying to add SonarQube integration to our Jenkins build server. I followed the instructions from our in-house server to setup Jenkins then downloaded sonarqube-build-wrapper-linux-x86.zip and installed the files on the build agent in the PATH. We’re using a multibranch pipeline build configured by Jenkinsfile in the source repo so I setup a test branch with:
But there doesn’t seem to be a sonar-scanner executable installed. sonarqube-build-wrapper-linux-x86.zip contains:
build-wrapper-linux-x86-64
libinterceptor-haswell.so
libinterceptor-i686.so
libinterceptor-x86_64.so
and I can run build-wrapper-linux-x86-64 -h fine. Is sonar-scanner supposed to be included in the zip?
Also, this code doesn’t work in Jenkins - I get:
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
WorkflowScript: 29: Not a valid stage section definition: "def scannerHome = tool 'SonarScanner 4.0'". Some extra configuration is required. @ line 29, column 9.
stage('SonarQube analysis') {
^
WorkflowScript: 29: Unknown stage section "withSonarQubeEnv". Starting with version 0.5, steps in a stage must be in a ‘steps’ block. @ line 29, column 9.
stage('SonarQube analysis') {
^
WorkflowScript: 29: Expected one of "steps", "stages", or "parallel" for stage "SonarQube analysis" @ line 29, column 9.
stage('SonarQube analysis') {
^
3 errors
Looking around some of the previous questions here made me realise that build-wrapper-linux-x86-64 is literally a build wrapper, so should be used like this:
stage('SonarQube analysis') {
steps {
withSonarQubeEnv('My SonarQube Server', envOnly: true) {
// This expands the evironment variables SONAR_CONFIG_NAME, SONAR_HOST_URL, SONAR_AUTH_TOKEN that can be used by any script.
println ${ env.SONAR_HOST_URL }
}
}
}
but I get:
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
WorkflowScript: 32: ${ env.SONAR_HOST_URL } cannot be used as a value directly. Did you mean "${ env.SONAR_HOST_URL }"? (add quotes) @ line 32, column 29.
println ${ env.SONAR_HOST_URL }
^
WorkflowScript: 30: Arguments to "withSonarQubeEnv" must be explicitly named. @ line 30, column 17.
withSonarQubeEnv('My SonarQube Server', envOnly: true) {
^
2 errors
I think maybe the vanilla scanner - the one you need - used to be distributed to Maven Central, but probably not any more. I’m going to raise this to the docs team; we probably need to take a look at that.
In the meantime, you can download the scanner from here.
I’ve changed Jenkins to install from the .zip listed on that page but it’s still failing to find sonar-scanner. Does the install get triggered by something like withSonarQubeEnv in Jenkinsfile? In which case what’s the format for this, because I keep getting errors when I try to add it.
Should I be able to see the .zip being installed in the Jenkins log?