Hi…Im trying to execute the below script from jenkins pipeline but its failing. Till the sonar analysis is successful but the quality gate is failing. I created a webhook in sonar server which is returning the json. Getting error “Invalid JSON String”. Please help.
Below analysis, its going till the “test3” further its failing to read status waitForQualityGate(). Please advise.
stage('Sonarqube Analysis') {
environment {
scannerHome = tool 'ALM Sonar'
}
steps {
withSonarQubeEnv('ALM Prod Sonar') {
sh "${scannerHome}/bin/sonar-scanner"
}
echo "test1"
sleep time: 30000, unit: 'MILLISECONDS'
echo "test2"
script {
echo "test3"
def qg = waitForQualityGate()
echo "test4"
if (qg.status != 'OK') {
//error "Pipeline aborted due to quality gate failure: ${qg.status}"
echo "test4"
}
}
}
}
-----------------------------------------
INFO: Analysis total time: 14.954 s INFO: ------------------------------------------------------------------------ INFO: EXECUTION SUCCESS INFO: ------------------------------------------------------------------------ INFO: Total time: 25.860s INFO: Final Memory: 53M/842M INFO: ------------------------------------------------------------------------
[Pipeline] }
[Pipeline] // withSonarQubeEnv
[Pipeline] echo test1
[Pipeline] sleep Sleeping for 30 sec
[Pipeline] echo test2
[Pipeline] script
[Pipeline] {
[Pipeline] echo test3
[Pipeline] waitForQualityGate Checking status of SonarQube task 'AXFP4RjqYkl4E6gsvEaH' on server 'ALM Prod Sonar'
[Pipeline] }
[Pipeline] // script
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Declarative: Post Actions)
[Pipeline] emailext Sending email to: rama.krishna.kandi@accenture.com [Pipeline] } [Pipeline] // stage
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline hudson.remoting.ProxyException: net.sf.json.JSONException: Invalid JSON String
Sonrscanner version - 3.0.0.702
Json output in sonar webhook:
{
"serverUrl": "http://localhost:9000",
"taskId": "AXFP4RjqYkl4E6gsvEaH",
"status": "SUCCESS",
"analysedAt": "2020-04-06T14:24:32+0000",
"revision": "e411d9d79323381d6655edbe98fa229cb7cde460",
"changedAt": "2020-04-06T14:24:32+0000",
"project": {
"key": "adop:SDSPDVCR:baggagetracking",
"name": "StarDSP-BaggageTracking-Test",
"url": "http://localhost:9000/dashboard?id=adop%3ASDSPDVCR%3Abaggagetracking"
},
"branch": {
"name": "master",
"type": "LONG",
"isMain": true,
"url": "http://localhost:9000/dashboard?id=adop%3ASDSPDVCR%3Abaggagetracking"
},
"qualityGate": {
"name": "Sonar way (outdated copy)",
"status": "ERROR",
"conditions": [
{
"metric": "new_coverage",
"operator": "LESS_THAN",
"value": "20.0",
"status": "ERROR",
"errorThreshold": "80"
},
{
"metric": "new_blocker_violations",
"operator": "GREATER_THAN",
"value": "0",
"status": "OK",
"errorThreshold": "0"
},
{
"metric": "new_critical_violations",
"operator": "GREATER_THAN",
"value": "0",
"status": "OK",
"errorThreshold": "0"
},
{
"metric": "new_sqale_debt_ratio",
"operator": "GREATER_THAN",
"value": "1.1111111111111112",
"status": "OK",
"errorThreshold": "5"
}
]
},
"properties": {}
}