Jenkins plugin does not process webhook from PR analysis

Using SonarQube 8.3 Developer edition

I have recently started using SonarQube 8.3 to take advantage of the auto-detection of branches and PRs for analysis.

This works well and my branch builds and my PR builds are appropriately identified.

I am using the SonarQube Jenkins plugin and have the following stage:

stage("Sonar Quality Gate") {
    agent none
    steps {
        timeout(time: 1, unit: "HOURS") {
            waitForQualityGate abortPipeline: true
        }
    }
}

When I make a commit on a branch with an open PR, two builds will be kicked off. One branch build and one PR build.

Since moving to 8.3, Sonar is now detecting the PR build and doing PR analysis. The problem is that when the analysis completes and the webhook is sent it is not detected by the plugin so the PR build just hangs around waiting.

The branch build on the other hand receives the webhook as expected and proceeds on to the next stage.

I have confirmed that both webhooks are sent and received by checking /admin/webhooks -> Recent Deliveries. I see a 200 OK status for both webhooks.

The SonarQube jenkins plugin version is 2.11.

To reproduce create a Jenkins job that builds both branches and PRs with a waitForQualityGate() stage. Make a commit to kick off both builds.

Expected behaviour:

  1. Branch based sonar analysis completes
  2. Branch based webhook is sent
  3. Branch based build continues or fails depending on webhook response
  4. PR based sonar analysis completes
  5. PR based webhook is sent
  6. PR based build continues or fails depending on webhook response

Actual behaviour:

  1. Branch based sonar analysis completes
  2. Branch based webhook is sent
  3. Branch based build continues or fails depending on webhook response
  4. PR based sonar analysis completes
  5. PR based webhook is sent
    6. PR based build does not process the webhook and continues to wait

Hi,

Is it possible that your situation is covered by this ticket?

SONARJNKNS-320 - waitForQualityGate could get stuck

Or do you really see this as something else?

 
Ann

I think this is something else.

I have two jobs running (one branch based and one PR based). Two webhooks are sent and the branch one is always processed successfully. The PR one is always missed.

If it was related to https://jira.sonarsource.com/browse/SONARJNKNS-320 I would expect this to randomly impact both the branch build and the PR build.

Is there anything else that I can do to help confirm this as an issue and get it looked at?

Or can someone point me in the right direction of the code base and I can have a look myself?

Hi Rob,

I’m taking a look as well, but you are welcome to join the hunt.
The source for the Quality Gate step is located here: https://github.com/SonarSource/sonar-scanner-jenkins/tree/master/src/main/java/org/sonarsource/scanner/jenkins/pipeline

Cheers,
Mark

This seems to match oddities that I have seen. We build in Jenkins using a GitHub “discover branches” behaviour configured for “Exclude branches that are also filed as PRs”. Occasionally, the PR pipeline will get stuck during quality gate, exactly as described in SONARJNKNS-320.

Once the PR build has failed in this way it then always fails for the same reason.

The solution for us is always the same and always works…

  • Change the job configuration so that discover branches = all branches.
  • Build the branch that was the basis for the PR. The QG passes.
  • Build the PR again. The QG passes. Nothing gets stuck.
  • PR can now be merged.
  • Changed pipeline configuration back to “Exclude branches that are also filed as PRs” (the bug strikes randomly and maybe 98% of our PRs have no QG issue).