Must-share information (formatted with Markdown):
-
which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)
SonarQube 7.9.1 (on a remote server)
Sonar maven plugin 3.7.0.1746 (in my pom.xml file)
Jenkins 2.222.1 (local server)
Maven 3.6.0 -
what are you trying to achieve
Try to get sonar’ quality gate result -
what have you tried so far to achieve this
Here is below my pipeline. On my Sonar server, the server is said unreachable. When I try to connect to myjenkins/sonarqube-webhook/
I have first :This URL requires POST
and when I try again with a post I haveHTTP ERROR 400 Invalid JSON Payload
.
Yet, the quality gate result is quite clear :"serverUrl": "https://****/sonar", "taskId": "AXGHZCWeQLkOZHj6Wg_V", "status": "SUCCESS", "analysedAt": "2020-04-17T09:06:51+0000", ...
```pipeline{
agent {
label "master"
}
tools {
// Note: this should match with the tool name configured in your jenkins instance (JENKINS_URL/configureTools/)
maven "Maven 3.6.0"
jdk 'Java 1.8'
}
environment {
// This can be nexus3 or nexus2
NEXUS_VERSION = "nexus3"
// This can be http or https
NEXUS_PROTOCOL = "http"
// Where your Nexus is running
NEXUS_URL = "192.168.1.8:8081"
// Repository where we will upload the artifact
NEXUS_REPOSITORY = "repository-example"
// Jenkins credential id to authenticate to Nexus OSS
NEXUS_CREDENTIAL_ID = "nexus-credentials"
}
stages {
stage ('Initialize') {
steps {
sh '''
echo "PATH = ${PATH}"
echo "M2_HOME = ${M2_HOME}"
'''
}
}
stage("mvn clean deploy") {
steps {
script {
// If you are using Windows then you should use "bat" step
// Since unit testing is out of the scope we skip them
sh "mvn -B clean deploy"
}
}
}
stage ("SonarQube check") {
steps {
script {
sh 'mvn -B -X sonar:sonar'
qualitygate = waitForQualityGate()
if (qualitygate.status != "OK") {
currentBuild.result = "UNSTABLE"
}
}
}
}
}
}```
I have also tried to follow the documentation with this type of pipeline :
```stage ("SonarQube check") {
steps {
withSonarQubeEnv('SonarTiss') {
sh '-B -X sonar:sonar'
}
}
}
stage("Quality Gate") {
steps{
timeout(time : 1, unit : 'HOURS'){
waitForQualityGate abortPipeline: true
}
}
}```
But then I have this error :
``` Injection des variables d'environnement SonarQube en utilisant la configuration: SonarTiss
[Pipeline] {
[Pipeline] sh
+ -B -X sonar:sonar
/var/lib/jenkins/workspace/Pipe_Jeu_Alexis@tmp/durable-7968e6b1/script.sh: 1: /var/lib/jenkins/workspace/Pipe_Jeu_Alexis@tmp/durable-7968e6b1/script.sh: -B: not found
[Pipeline] }
WARN: Unable to locate 'report-task.txt' in the workspace. Did the SonarScanner succeeded?
[Pipeline] // withSonarQubeEnv
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Quality Gate)
Stage "Quality Gate" skipped due to earlier failure(s)
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: script returned exit code 127
Finished: FAILURE```