Pull-request from GitHub unable to resolve branches

Must-share information (formatted with Markdown):

  • which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)
    SonarQube 8.3 Developer Edition
  • what are you trying to achieve
    Analysis of PR occasionally fails to properly annotate due to branch resolution failure. Log shows:
10:07:26  [INFO] Load project branches
10:07:26  [INFO] Load project branches (done) | time=55ms
10:07:26  [INFO] Load project pull requests
10:07:26  [INFO] Load project pull requests (done) | time=53ms
10:07:26  [INFO] Load branch configuration
10:07:26  [INFO] Load branch configuration (done) | time=5ms
10:07:26  [INFO] Load quality profiles
10:07:26  [INFO] Load quality profiles (done) | time=95ms
10:07:26  [INFO] Detected Jenkins
10:07:26  [INFO] Load active rules
10:07:26  [INFO] Load active rules (done) | time=1396ms
10:07:26  [INFO] Pull request 319 for merge into 2.17.131.77089.2-pre-submitter-enhancements from 2.17.131.77089.3-submitter-refactor
10:07:26  [INFO] SCM collecting changed files in the branch
10:07:26  [WARNING] Could not find ref: 2.17.131.77089.2-pre-submitter-enhancements in refs/heads or refs/remotes/origin
10:07:26  [INFO] SCM collecting changed files in the branch (done) | time=54ms
  • what have you tried so far to achieve this
    Correctly identifying branch revisions with properties:
sonar.pullrequest.branch=2.17.131.77089.3-submitter-refactor
sonar.pullrequest.base=2.17.131.77089.2-pre-submitter-enhancements
sonar.pullrequest.key=319 

Hi Mark!

Generally the underlying issue in a situation like this is the git checkout upon which the analysis was run is too shallow. Is this running on a CI system like Jenkins?

You can work around it possibly by tuning settings involved in the checkout, or with brute force in the script involved in your build/pipeline using something like this:

git fetch --no-tags ${GIT_URL} +refs/heads/master:refs/remotes/origin/master

Obviously this example would apply if the PR target was master. In your case it looks like it’s 2.17.131.77089.2-pre-submitter-enhancements (holy specific branch name, Batman!) so adjust accordingly.

Hope this helps!

1 Like