Qualitygate failure with no boday to invoke jenkins pipeline error

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": {}
}

Hi,

Welcome to the community!

A couple things occur to me. First, you’ve got a lot going on in the pipeline snippet you shared. Why nest checking the QG in a script node? What happens if you don’t nest it? Also - and I really don’t know the implications of this - the docs show checking the QG status as a different stage. Have you tried it like that?

And finally, your logs indicate that a few other things happen between analysis & checking the QG status and the JSON error you’re getting. So why the assumption that the error is related to analysis?

 
Ann

Hi Ann,

Thank you so much for your kind reply. I already referred the sonar document you shared and …I tried with both scripted and declarative pipeline script even by separating the stages but getting errors below. Please correct me if im doing wrong. Thank you.

Scripted pipeline

WorkflowScript: 59: Unknown stage section “sleep”. Starting with version 0.5, steps in a stage must be in a ‘steps’ block. @ line 59, column 8.
stage(‘Quality Gate’) {
^

WorkflowScript: 59: Unknown stage section “timeout”. Starting with version 0.5, steps in a stage must be in a ‘steps’ block. @ line 59, column 8.
stage(‘Quality Gate’) {
^
WorkflowScript: 59: Expected one of “steps”, “stages”, or “parallel” for stage “Quality Gate” @ line 59, column 8.
stage(‘Quality Gate’) {
^

code snippet :
stage(‘Sonarqube Analysis’) {
environment {
scannerHome = tool ‘ALM Sonar’
}
steps {
withSonarQubeEnv(‘ALM Prod Sonar’) {
sh “{scannerHome}/bin/sonar-scanner" } } } stage('Quality Gate') { sleep time: 3000, unit: 'MILLISECONDS' timeout(time: 1, unit: 'MINUTES') { def qg = waitForQualityGate() if (qg.status != 'OK') { error "Pipeline aborted due to quality gate failure: {qg.status}”
}
}
}


Declarative pipeline -

For declarative pipeline getting below error - Invalid parameter “abortPipeline”, did you mean “null”?
ERROR :
Running in Durability level: MAX_SURVIVABILITY
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
WorkflowScript: 64: Invalid parameter “abortPipeline”, did you mean “null”? @ line 64, column 40.
waitForQualityGate abortPipeline: true

Code -
stage(‘Sonarqube Analysis’) {
environment {
scannerHome = tool ‘ALM Sonar’
}
steps {
withSonarQubeEnv(‘ALM Prod Sonar’) {
sh “${scannerHome}/bin/sonar-scanner”
}
}
}
stage(“Quality Gate”) {
steps {
timeout(time: 1, unit: ‘HOURS’) {
// Parameter indicates whether to set pipeline to UNSTABLE if Quality Gate fails
// true = set pipeline to UNSTABLE, false = don’t
waitForQualityGate abortPipeline: true
}
}
}

Hi,

I think your first step is to master one of these two examples, you can then iterate and build from there.

 
Ann

Sorry Ann. I didn’t understand your directions. Just wanted to know why Im getting “Invalid parameter “abortPipeline”, did you mean “null”?” for the above declarative pipeline. Am I missing something? Please advise. Thank you.

Hi,

In the initial post in this thread, you show a log that ends with Invalid JSON String. I eventually advised you to pick one of the examples from the docs and master it. You seem to be getting errors when you try to incorporate the examples into your existing pipeline. Perhaps you should pare back to just the examples in the docs: get them to work, then you can layer in your other commands. I don’t know off-hand why you’re getting that error, but I’m willing to bet it has to do with how you’ve incorporated the example into your existing pipeline.

 
:woman_shrugging:
Ann

Hi Ann,

Thank you for your detailed directions. I just build the pipeline from scratch and tested by adding each step. But it still failing at waitForQualityGate with “abortPipeline”, did you mean “null”?”. Any clue? Thank you.

Hi,

What’s the most minimal pipeline code where you get that error?

 
Ann

Below is the basic pipeline im trying to build. checkout the scm, maven build and packaging then sonar analysis. It is working fine till sonar analysis. Once I add the quality gate its failing with error.

pipeline {
    agent {
        label 'maven-jdk-8'
    }
    stages {
        stage('Prepare dependencies') {
            steps {
                dir("proxy-common/common-maven-dependencies") {
                    sh "chmod +x install-custom-dependencies.sh"
                    sh "./install-custom-dependencies.sh"
					}
				}
			}
			stage('Upload code to test revision (rev2)') {
            steps {
                    sh 'mvn package'
                    }
				}
			}
			stage('Sonarqube Analysis') {
            environment {
				scannerHome = tool 'ALM Sonar'
		    }
			steps {
				withSonarQubeEnv('ALM Prod Sonar') {
					sh "${scannerHome}/bin/sonar-scanner"
				}
				
			}	
					
        }
		stage("Quality Gate") {
            steps {
                timeout(time: 1, unit: 'HOURS') {
                waitForQualityGate abortPipeline: true
                }
            }
        }
    }
}

Hi,

I edited your post to code-format your pipeline code (``` on the line before and on the line after). Once I did that, I noticed that your close curly braces didn’t line up vertically with your open curly braces. I started to edit again to fix that and stopped because I realized that you don’t have the same number of each.

A decent text editor (I use Geany on Linux and I know Notepad++ is good for windows) will help you find the mismatch, which is likely your underlying problem.

To be pedantic and annoying, this is kinda why I advised you to go to the smallest possible pipeline code, get it to work, and then add from there.

 
Ann

Is the error related to format issue? I didnt get any syntax issue during the execution and Im using notpad++ to format the code. If I miss any curly braces, the pipeline will immediately fail with syntax error.

Hi Ann,

Sorry. I missed some braces while copying the code. Below is the updated code. hope this works. Just followed the reference document and I executed stage by stage. Its working till sonar analysis. Later its failing at quality gate. Not sure what mistack Im doing.

pipeline 
{
    agent any
    stages 
	{
        stage('Prepare dependencies') 
		{
            steps 
			{
                dir("proxy-common/common-maven-dependencies") 
				{
                    sh "chmod +x install-custom-dependencies.sh"
                    sh "./install-custom-dependencies.sh"
                }
            }
        }
		
		stage('Upload code to test revision (rev2)') 
		{
            steps 
			{
                {
                    sh 'mvn package'
                    
                }
            }
        }
		stage('Sonarqube Analysis')
		{
            environment
			{
				scannerHome = tool 'ALM Sonar'
		    }
			steps
			{
				withSonarQubeEnv('ALM Prod Sonar') 
				{
					sh "${scannerHome}/bin/sonar-scanner"
				}
				
			}	
        stage("Quality Gate")
		{
            steps
			{
                timeout(time: 1, unit: 'HOURS')
				{
                    waitForQualityGate abortPipeline: true
                }
            }
        }
    }
}

Hi ,

I am also getting same error ( Invalid parameter “abortPipeline”, did you mean "null)

Did you get any fix ?

Regards

Unni