Reputation: 1106
I followed the docs available on : https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner+for+Jenkins
However, I cannot get it to work.
First it appears that the docs need updating because the syntax in the example is wrong. In the latest version of declarative pipelines, steps
is mandatory inside the stage
-tag.
Also, the def
-keyword only gets resolved when it is inside a script
-tag.
Beside that, when running Jenkinsfile below, I receive a NPE:
java.lang.NullPointerException
at org.jenkinsci.plugins.workflow.steps.ToolStep$Execution.run(ToolStep.java:150)
at org.jenkinsci.plugins.workflow.steps.ToolStep$Execution.run(ToolStep.java:133)
at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution$1$1.call(SynchronousNonBlockingStepExecution.java:49)
at hudson.security.ACL.impersonate(ACL.java:290)
at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution$1.run(SynchronousNonBlockingStepExecution.java:46)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Jenkinsfile
pipeline {
environment {
scannerHome = tool 'SonarQube Scanner 3.2.0.1227'
}
agent {
node {
label "master"
}
}
options {
buildDiscarder logRotator(daysToKeepStr: '7')
}
stages {
stage("Sonarqube analysis") {
steps {
withSonarQubeEnv('SonarQube Scanner') {
bat "${scannerHome}/bin/sonar-scanner"
}
}
}
Upvotes: 2
Views: 1567
Reputation: 1106
Fixed it with the following:
pipeline {
agent {
node {
label "master"
}
}
stages {
stage("SonarQube analysis") {
steps {
script {
def sonarScanner = tool name: 'SonarQube', type: 'hudson.plugins.sonar.SonarRunnerInstallation'
bat "${sonarScanner}/bin/sonar-scanner -e -Dsonar.host.url=xxx"
}
}
}
}
}
Upvotes: 1