which versions are you using (SonarQube Server / Community Build, Scanner, Plugin, and any relevant extension)
dotnet-sonarscanner ver 9.x
how is SonarQube deployed: zip, Docker, Helm
deployed as global dotnet tool in a Docker image
what are you trying to achieve
Attempting to run an analysis of a “dotnet build” on a PR request and have the results get pushed into SonarCloud.
what have you tried so far to achieve this
The analysis is able to run and the results are pushed, however the results are not accepted due to the analysis believing it cannot find the base branch of the PR branch being analyzed. This is due to the command line of the base branch having double quotes around it. In our case, it was the develop branch. When we passed /d:sonar.pullrequest.base=develop, the analysis worked and was accepted. When we passed /d:sonar.pullrequest.base=“develop” as the command tail, the analysis complained about not finding the branch “develop” in the /ref/heads of git. We would like to use quotes so that we can protect the commandline from characters that can cause it to create a malformed argument. For now, we need to special case this scenario and remove quotes when the base branch is “develop” or “master”. Do not share screenshots of logs – share the text itself (bonus points for being well-formatted)!
sonarissue.txt (12.4 KB)
Line 93 of the log demonstrates how the double quotes surrounding the branch name are preserved and used literally. This is what clued me in to the issue being the double quotes. Once I removed them from the command line, I didn’t get the error with it not finding the branch “develop” within SonarCloud anymore.
I’ve also attached build log of the step working once I removed the double quotes from the commandline arguments sonarworking.txt (14.4 KB)
The sonarscanner tool is installed into our teamcity build agent and leveraged from within the dockerfile attached.
I looked at the code a bit and it might be due to this line:
Not familiar with the code, but it appears the commandline parser may not have as much smarts as we would like it to have at first glance. I always use the nuget package CommandLineParser when I need to do command arg parsing work…its solid and has never let me down when it comes to parsing all of the flavors of command arguments with no problems.
Thanks a lot – this makes more sense to me. I was thinking that the value for sonar.pullrequest.branch was getting used elsewhere by the scanner, not by the Scanner for .NET in pre-processing. I’ll flag this for attention.
Thanks for reporting. This looks like a bug on our side. I created an internal ticket for investigation. We will let you know here when we start working on it.