Sonarqube Could not find ref 'develop'

  • SonarQube 9.5 Developer EDition (build 56709)
  • Deployed on premise on local server
  • Im trying to use quality gate integration with bitbucket

I build a feature that has a pull request ona branch feature/yyy-yyy-yyy. The pull request is shown i Sonarqube as expected. the branch originates from develop. I have several issues on the feature that should be shown in SonarQube. But the “measures” on the pull request says there are no issues found. The “Code” page on the pull request in SonarQube says 0 new lines of code even though there are 100s of new lines.

Im building my source with the sonarwrapper in a docker container. When analyzing the code on the pull request SonarQube gives a warning:

Could not find ref 'develop' in refs/heads, refs/remotes, refs/remotes/upstream or refs/remotes/origin. You may see unexpected issues and changes. Please make sure to fetch this ref before pull request analysis and refer to the documentation.

When i run a git show-refs in my jenkins pipeline i see the following:

+ git show-ref
6a82f... refs/remotes/bitbucket_prod/bugfix/xxx-xxx-xxx
6a82e... refs/remotes/bitbucket_prod/develop
261d2... refs/remotes/bitbucket_prod/feature/yyy-yyy-yyy

I have the branch feature/yyy-yyy-yyy checked out when running the analysis.

I’m wondering if sonarqube does not find develop because it is not under the standard “origin” remote. Or is there some other possible problem. We do not run submodules.

We are integrated with BitBucket. The problem is taha Sonarqube always believe that there are nothing changed since it can not find develop.

The project is setup to use develop as reference branch, except for develop that uses previous version. Analysis of develop works fine. ITs the analysis of the delta between my branch yyy-yyy-yyy and develop that does not work.

Any idea of what I can try?

Hey there.

Probably.

I’m not sure I’ve actually seen this before – can you discuss your setup and why it’s not under the “standard” origin/remote?

It the way we set up the origin in our pipelines. I tried to set the remote name to origin, and then it works. Perhaps it could be a good idea to be able to specify remote name in e.g., sonar-project.properties file as you can have several remotes in a git repo.

Just to provide some more context, you can find the list of hard-coded refs we look at here:

    String localRef = "refs/heads/" + targetBranchName;
    String remotesRef = "refs/remotes/" + targetBranchName;
    String originRef = "refs/remotes/origin/" + targetBranchName;
    String upstreamRef = "refs/remotes/upstream/" + targetBranchName;

Still, it’s an interesting question. We’ll discuss this internally to see if we would indeed want to support “custom” remotes.

1 Like

With the second case listed, custom remotes should be supported by specifying, for example, bitbucket_prod/feature/yyy-yyy-yyy, unless there’s a bug linked specifically to branch references.

See [SONAR-13586] - Jira.

As @Wouter_Admiraal pointed out, that won’t work when setting the reference branch in the UI. It may work when passing sonar.newCode.referenceBranch to the scanner.