Sonar.target.branch not working in SonarCloud?

Hello community!
As mentioned on Branch analysis setup the sonar.branch.target parameter can be used to specify a base branch for the new code definition of short-living branches.
However, our attempts with this fail - only the project’s main branch is displayed as the reference branch.
The parameter is also not mentioned on Analysis Parameters.

Is the parameter still supported or not? Either one of the documentation pages seems to be wrong.

We use:

  • Jenkins Pipelines
  • Maven Scanner (sonar-maven-plugin 4.0.0.4121)

I have tried to specify the parameter via command line parameter (-D) or via pom property.

Thanks!

Hey there.

Indeed, sonar.branch.target is supported in SonarCloud.

Have you also configured sonar.branch.name?

Hey Colin, thank you for your reply!
Yes, I did it like:

mvn sonar:sonar -Dsonar.branch.name=${BRANCH_NAME} -Dsonar.branch.target=development

But on the branch’s dashboard, it was still referencing “master” (main branch).

Btw. shouldn’t Analysis Parameters also mention the two sonar.branch.* parameters?

Hey!

I think you’ve just got your parameters mixed up.

sonar.branch.name should be the name of the branch you want to analyze, and sonar.branch.target is the name of the branch you imagine you will eventually merge into.

It’s… debatable, since we mention them in our branch analysis docs. You can consider that we don’t list all our test coverage parameters in the analysis parameters docs either.

Anyways, I’ll throw it over to our Docs folks and let them decide. Thanks for the feedback!

1 Like

No, I think that’s correct. The BRANCH_NAME environment variable is set by Jenkins, it’s the branch of the current build. Target is “development” in this case, where the current branch has branched off and will be merged back later.

And you’re sure BRANCH_NAME isn’t resolving to master? An echo $BRANCH_NAME will confirm as much?

I don’t want it to seem like I’m not trusting you, but it is not a complicated parameter.

Just to show you how it’s working on my machine, against SonarCloud:

mvn sonar:sonar -Dsonar.branch.name=test -Dsonar.branch.target=main -X
...
[DEBUG] 18:21:38.328 Branch name: test, type: short-lived

Thank you Colin, I will give it a try tomorrow.

1 Like