Same code passing branch analysis but failing pull request analysis

Must-share information (formatted with Markdown):

  • which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension):
    • SonarQube Enterprise 10.3
  • how is SonarQube deployed:
    • Helm
  • what are you trying to achieve?
    • Setting up quality gate to block PR from merging
  • what have you tried so far to achieve this?
    • We currently have sonar-scanner set up to execution in our CI being called from a python script which injects the necessary properties depending on the context.
    • If the script detects that a pull request has not been opened yet then it’ll only pass sonar.branch.name to the command, otherwise it’ll include the necessary properties for pull request analysis
    • In both scenarios, we always pass sonar.qualitygate.wait=true
    • On a feature branch, I’ve added some code with no tests. When I push the change to github to trigger our CI, sonar-scanner will pass and it shows in the Web UI that the change has pass the quality gate.
    • Afterwards, I open a PR without making any additional changes then re-run the same CI pipeline and now sonar-scanner reports that we are failing the quality gate with 0% coverage.

Is there something different with how new code is detected between branch vs pull request analysis?

Hi,

There shouldn’t be.

Can you share the analysis log from both the branch and the PR analysis?

The analysis / scanner log is what’s output from the analysis command. Hopefully, the log you provide - redacted as necessary - will include that command as well.

This guide will help you find them.

 
Ann

I think I found the problem to the issue I was running into. I wasn’t passing in sonar.newCode.referenceBranch property to sonar-scanner causing it not able to properly calculate the metrics.

1 Like