Log sonarqube webhook JSON payload in jenkins

I am trying to log the output of the sonarqube webhook JSON payload within jenkins stage. It seems the JSON payload is trimmed to just the status of the webhook. No other data remains accessible. Below snippet might help. (NodeJS project and thus npm run used)

stage('SonarQube Analysis') {
  withSonarQubeEnv('sonarQube-8.5') {
    sh 'npm install sonar-scanner'
    echo 'Starting SonarQube Analysis'
    sh 'npm run analyse -- -Dproject.settings=./sonar-project.global.properties'
stage("Sonar Quality Gate") {
  timeout(time: 10, unit: 'MINUTES') {
    def quality_gate_result = waitForQualityGate()
    if (quality_gate_result.status != 'OK') {
      error "Pipeline aborted due to quality gate failure: ${quality_gate_result.status}"
    } else {
      echo 'Sonar Quality Gate passed'

Any help appreciated. Thanks

Welcome :slight_smile:

you have to setup a logger in Jenkins like that =

The log has the full payload.
If you need to show it in Jenkins pipeline console log also you may parse those logs,
see $JENKINS_HOME/logs/custom/SonarQube.log with log rotation.
As the payload in the log has the analysisid you should be able get the right one.


Is there a way to extract the webhook payload from waitForQualityGate function or its response ?. I believe there has to be a way around.

Beside the way via Jenkins log file parsing, you may also use the Sonarqube web api.

First parse the /sonar/report-task.txt in Jenkins workspace of your pipeline and grep
the ceTaskId or alternatively the projectKey

Then use
or alternatively
to get all deliveries with their deliveryIds.

Finally use the deliveryId you’re interested in to get its payload, i.e.