Atlassian Bitbucket Cloud Pull Request Pipeline: Error "Pull request with branch does not exist on server: epic-foo-bar"


(Nico) #1

When runnning a pull request against an epic branch (commonly we run against “develop”), sonar cloud complains in the bitbucket pipeline with an error message that such a branch would not exist on the server.

ERROR: Error during SonarQube Scanner execution
ERROR: Pull request with branch does not exist on server: epic-foo-bar

Which puzzles me a bit. Which server is that? Bitbucket for sure has that branch and the command line contains a lot of configuration:

sonar-scan: \
	sonar-scanner \
		-Dsonar.pullrequest.key=1234 \
		-Dsonar.pullrequest.base=epic-foo-bar \
		-Dsonar.pullrequest.branch=test-my-epic-foo-bar-blue \
		-Dsonar.pullrequest.provider=Bitbucket \
		-Dsonar.pullrequest.bitbucket.repository=vendor/reponame

Me is a bit puzzled here. Isn’t it possible to use different branches as pull request targets?


(Muddsar) #2

You need to use sonar.branch.target to set the pull request target branch


(Nico) #3

I can’t find this property documented for the feature, this is the documentation I followed IIRC: https://docs.sonarqube.org/latest/analysis/pull-request/

Do you have this working on Atlassian Bitbucket Cloud w/ the Pipelines Plugin pushing the analysis to the Sonarsource Sonarcloud.IO webapplication? Just double checking.

/E: I trried your suggestion and it’s producing another error that is “Caused by: A pull request analysis cannot have the branch analysis parameter ‘sonar.branch.target’” the error is: " ERROR: Error during SonarQube Scanner execution\njava.lang.IllegalStateException: Unable to load component class org.sonar.scanner.scan.ProjectSettings"


(Julien Henry) #5

Hi @NicoNico

When analyzing a PR, SonarCloud currently needs a base (long living) branch analysis to identify new issues. Since your PR is targeting the branch “epic-foo-bar”, this branch have to be analyzed first on SonarCloud.

Assuming ‘epic-foo-bar’ will be ultimately merged into your ‘develop’ branch, you can either:

  • analyze ‘epic-foo-bar’ as a short living branch: sonar-scanner -Dsonar.branch.name=epic-foo-bar [-Dsonar.branch.target=develop]
  • open a pull request between ‘epic-foo-bar’ and ‘develop’ and analyze it on SonarCloud

I admit all that is pretty complex, due to technical reasons you should have to care of. We are working on making the PR analysis much more simpler.

Out of curiosity, are you using Bitbucket Pipelines?

BTW I encourage you to look at the SonarCloud documentation: https://sonarcloud.io/documentation/analysis/pull-request/
since the parameter -Dsonar.pullrequest.bitbucket.repository=vendor/reponame is wrong.


(Nico) #6

Cheers @Julien_HENRY, I also was playing with “sonar.branch.name” as I figured out the branch was missing on Sonarcloud (which is what the error says), so thanks for confirming and more detailed feedback. Will give the branch target a try, this looks good in our case.

And it’s not that complex, I’m using Bitbucket Pipelines in conjunction with this local pipeline runner (ktomk/pipelines) with which I can trigger the initial branch analysis - at least that is the plan so far.

Also thanks for pointing out the wrong parameters, I don’t see any errors for those but I’ll update them to the current docs. When I started using that feature this was all a bit less documented then and I was happy when I got it to work.


(Julien Henry) #7

If you are using Bitbucket Pipelines, don’t set any sonar.branch.* or sonar.pullrequest.* parameter. We will automatically guess them from environment variables (works for branches and new pull request builds).


(Nico) #8

@Julien_HENRY Thanks for the follow-up, have different build pipelines depending whether it’s a pull request pipeline or a branch (reference) push. What I learned in the past is that it was much more safe to set the required parameters explicitly instead of just trying out. I should be able to check if what your write (which totally makes sense) works in my scenario if you provide the list of environment variables that can be used to control the CLI agent (and a changelog as I hink this is version dependent).

And now for the branch analysis, this is a custom pipeline (that is manually triggered on a certain revision / branch) - so this would be really great if I could test w/ environment variable profiles.