Code is empty on PullRequest in GoCD

Hi Sonar Team!


SonarQube 7.7 on-prem
Sonar Scanning with Gradle plugin
GoCD as the CI
BitBucket for pull-requests

Experienced issue:

Running a pull-request analysis inside a pull-request pipelines:

  • does create a PR branch on Sonar, you can find it on the UI
  • it contains no code at all, and thus no issues
  • in BitBucket the SonarQube integration does pop-up, showing 0 issues and passed state

Expected result:

I have some new code in my pull-request that contains some issue. ( I put them there :slight_smile: ) I expect all new code to be visible on the Sonar UI, and for the new issues to be visible in Sonar UI, and annotated into the BitBucket pullrequest.

BitBucket-Sonar connection works

I configured the required properties. The summary is successfully created in BitBucket, even though it has 0 issues. The summary is also created/updated if I trigger the sonar preview build locally ( assuming I set the same properties that would be active in GoCD).

The properties required for preview annotations should be fine

If I set the same properties locally, and trigger the sonar analysis, everything seems to work fine. In Sonar the pr branch is updated, there is the code, and my fake issues are found. In BitBucket the issues are annotated correctly.

Probable cause

So it seems like in GoCD the stuff that is analysed is somehow different. I checked roughly, my files and fake issues are of course there. Maybe there might be some deeper issue with how the git checkout is really made.

If I check git branch in my local checkout, I get two results

  • the name of the feature branch I am working on. This is what I want to merge into master.
  • master

However checking the same command in GoCD only results in master. I’m not yet sure how much the Sonar scanner relies on the Git information. This could be an issue.

  • Does Sonar rely on git information directly, besides the sonar.pullrequest.branch parameter?
  • Does sonar.pullrequest.branch have to be precisely the git branch name for things to work, or is it rather a nice to have thing for easy comparison?

This issue around CircleCI is probably related, I did not yet try the suggestion there: No code or issue found in pull request decorations (github + circleci)

Thanks and cheers,

The scanner relies on sonar.pullrequest.base to compute the list of files that changed in the current branch, as well as the lines that changed. The referenced branch must be fetched, otherwise it will issue warning on the console, which also gets propagated to the UI, when you look at your pull request on SonarCloud. Isn’t there a warning? Check on SonarCloud UI, and also in the scanner output.

This parameter is only used to display the branch’s name on SonarCloud. It has no other technical purpose, and its value is typically overwritten with the display name of the PR on its ALM, such as GitHub and BitBucket.

1 Like