PR Decoration Not Showing in "Checks" On GitHub

Must-share information (formatted with Markdown):

  • which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)
    • Sonar Scanner Version - 4.2.0.1873
    • SonarQube Version - Developer EditionVersion 8.4.1 (build 35646)
  • what are you trying to achieve
    • Pull Request Decoration From SonarQube -> GitHub in a Jenkins CI pipeline
  • what have you tried so far to achieve this
    • Followed the steps outline here
      • Created a Github App with the proper permissions and installed it on the proper repositories
        • Read access to commits / metadata. Read / Write to checks and Pull Requests
      • Filled out Github App information In the Administration > ALM Integrations Tab
      • Applied settings to project (/api/alm_settings/get_binding?project=sporttrade_st-devops shows {"key":"sporttrade","alm":"github","repository":"sporttrade/st-devops","url":"https://api.github.com","summaryCommentEnabled":false})
      • Jenkins is using the Git Branch Source Plugin, so no extra parameters are passed during sonarqube scanning. Note - this runs in a Jenkins shared library if that has any impacts. An example run is shown below:
"sonar-scanner -Dsonar.projectKey=${this.project}" +
    " -Dsonar.exclusions=${this.exclusions}"

Also tried running with all PR decorator arguments:

"sonar-scanner -Dsonar.projectKey=${this.project}" 
    " -Dsonar.exclusions=${this.exclusions}" +
    " -Dsonar.verbose=true " +
    " -Dsonar.pullrequest.base=develop " +
    " -Dsonar.pullrequest.branch=${BRANCH_NAME} " +
    " -Dsonar.pullrequest.key=${env.CHANGE_ID} " +
    " -Dsonar.pullrequest.github.repository=org/repo-slug" +
    " -Dsonar.scm.revision=${env.GIT_COMMIT}"

The pull request is then properly shown in sonarqube, but no check is shown on the pull request. Tailing of the ce.log shows the following:

2020.11.10 12:22:05 INFO  ce[AXWyGxF3yLfJcA1jJqzv][o.s.c.t.s.ComputationStepExecutor] Trigger refresh of Portfolios and Applications | status=SUCCESS | time=0ms
2020.11.10 12:22:05 INFO  ce[AXWyGxF3yLfJcA1jJqzv][o.s.c.t.p.a.p.PostProjectAnalysisTasksExecutor] Webhooks | globalWebhooks=1 | projectWebhooks=0 | status=SUCCESS | time=21ms
2020.11.10 12:22:05 INFO  ce[AXWyGxF3yLfJcA1jJqzv][o.s.c.t.p.a.p.PostProjectAnalysisTasksExecutor] Pull Request decoration | status=SUCCESS | time=0ms
2020.11.10 12:22:05 INFO  ce[AXWyGxF3yLfJcA1jJqzv][o.s.c.t.CeWorkerImpl] Executed task | project=sporttrade_st-devops | type=REPORT | branch=REDACTED | branchType=BRANCH | id=AXWyGxF3yLfJcA1jJqzv | s

Image 1 - Snip of sonarqube UI

Image 2 - Snip of Checks PR on GitHub

If there is any other information I can provide, please let me know and thank you in advance.

I am experiencing similar results, using SonarQube 8.4.2, also 8.5.1 Developer Edition. Logs show PR decoration success, but analysis page shows warning about mis-configured pull-request properties. I am able to achieve successful PR decoration on a different project (uses same GitHub API app) although icons are not showing:

And now, magically, PR decoration is showing in conversation for both a new branch analysis and this same branch where it was missing yesterday!

Awesome! Are you using a CI runner like Jenkins to run your analysis? My analysis page shows no errors, so I’m not sure if I’m missing a parameter or if GitHub is deferring the request from SonarQube.

Yes, in Jenkins we call maven or gradle to invoke the request from the server. Have you setup the github app connection as described in https://docs.sonarqube.org/latest/analysis/pr-decoration/ ?

Yes, we have. Our GitHub App does communicate with SonarQube as we can import new SonarQube projects from GitHub through the SonarQube UI. It only seems to disconnect with PR decoration. Any thoughts on where to look?

@Alex_Foley,

If migrating to 8.5.1 is an option, I’d highly recommend that you do. We’ve improved logs around possible error in this version. That would help to investigate.

I’d also recommend that you verify your project settings for PR decoration: Project settings > Pull Request Decoration.

Feel free to share snapshot if you think it could help.

Cheers

@Philippe_Perrin thanks for responding. I attached the ALM/Project Settings images here.

Looks like your project configuration is fine.

Just out of curiosity, did you declare your Github App configuration through a SonarQube Enterprise edition?

As mentioned before, upgrading to SonarQube 8.5.1 might help the investigation. Is that an option?

No, it was declared through SonarQube Developer edition, would that be an issue? Upgrading to 8.5.1 is not an immediate option, but could be in the near future.

Not at all, I was just curious about the name of your Github configuration: sporttrade


You might want have a look at this documentation page, you’ll find information about PR decoration and Jenkins.

It is not clear to me how you run the scanner on the Jenkins side. Are you using our SonarQube plugin for Jenkins?

Also, setting log level to debug during the next PR analysis on SonarQube might help to gather more information. Go to /admin/system page.

Cheers

Yes, we use the SonarQube plugin for Jenkins, essentially something like the following:

stage('SonarQube Scan') {
      steps {
        script {
          withSonarQubeEnv('SonarqubeServer') {
            sh "sonar-scanner -Dsonar.projectKey=${env.project}  -Dsonar.sources=."
          }
        }
      }
    }

where env.project is the project key in sonarqube.

We also made sure to follow the documentation you provided as we use Multi-branch pipelines. However, it looks like support from that is supported in 8.5, and not in 8.4.

I’ll set the debug level a little bit higher and then check it out.

I did increase the log levels and noticed this:

2020.11.19 18:03:27 INFO  ce[AXXhrOJGyLfJcA1jJrFV][o.s.c.t.p.a.p.PostProjectAnalysisTasksExecutor] Webhooks | globalWebhooks=1 | projectWebhooks=0 | status=SUCCESS | time=31ms
2020.11.19 18:03:27 DEBUG ce[AXXhrOJGyLfJcA1jJrFV][c.s.C.B.B.A.A.E] POST response did not have expected HTTP code (was 404):
2020.11.19 18:03:27 DEBUG ce[AXXhrOJGyLfJcA1jJrFV][c.s.C.B.B.A.A.E] POST response did not have expected HTTP code (was 404):
2020.11.19 18:03:27 INFO  ce[AXXhrOJGyLfJcA1jJrFV][o.s.c.t.p.a.p.PostProjectAnalysisTasksExecutor] Pull Request decoration | status=SUCCESS | time=485ms

So it sent a web hook and received a 404, but it looks like this is directly before the Pull Request Decoration.

Hey @Alex_Foley .

You’re trying to integrate with Github.com on SonarQube v8.4.1. See this post for details on why you need to upgrade for PR Decoration to keep working.

(v8.4.2 is mentioned, but v8.5.1 is the latest version of SonarQube, and the only version you should target for an upgrade).

3 Likes

@Colin_SonarSource After upgrading to 8.5.1, I am no longer seeing the issue. Thank you for the helpful tip!