Using the "
withSonarQubeEnv" step in Jenkins pipeline (declarative syntax) running maven code coverage and sonar analysis results in a "
[ERROR] SonarQube server [http://localhost:9000] can not be reached" message. Other than running additional maven goals the pipeline is setup based on the
https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner+for+Jenkins#AnalyzingwithSonarQubeScannerforJenkins-AnalyzinginaJenkinspipeline docs. Is the
stages {
stage("Build") {
steps {
container('default') {
// change into app directory
dir('app') {
withSonarQubeEnv('my-sonar') { // there aren't any sonar env variables printed out
sh 'printenv'
sh "mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent install org.jacoco:jacoco-maven-plugin:report org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -P !sonar"
}
}
}
}
}
stage("Code Quality Gate") {
steps {
container('default') {
echo "Waiting for sonar results..."
script {
def qg = waitForQualityGate()
if (qg.status != 'OK') {
error "Pipeline aborted due to quality gate failure: ${qg.status}"
}
}
}
}
}
}
SonarQube Scanner for Jenkins v2.6.1
mvn --version
Apache Maven 3.3.9
Maven home: /usr/share/maven
Java version: 1.8.0_141, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-8-openjdk-amd64/jre
Default locale: en_US, platform encoding: ANSI_X3.4-1968
OS name: "linux", version: "4.13.5-coreos-r1", arch: "amd64", family: "unix"
Jenkins ver. 2.73.1