Sonar analysys failed due to Target Branch does not exist error

Hello,

we are using reference branch option for new code.
Whenever we are creating PR with new target branch Getting Target branch null error.

At present we are adding new target branch manually to Sonar projects. But it is difficult to predict and add all target branches prior to PR creation.

Is there any way to add Target branches automatically along with PR analysis?

  • Version 9.3 (build 51899)

Hey there.

It sounds like you should add a trigger to run SonarCloud analysis on the commit of any branch, which means those branches will always exist in SonarQube.

At least, this will cover any future branches that get created in your project.

Hello Colin,

Thanks for your response.

In our case if we run sonar scan for all branch commits, it takes much time for analysis and leads to redundant work.

Developers work on feature branches and raise PR to release branch, sonar scan runs at PR Build validation step.

we want to skip code scan on Release branches (code already analyzed in feature branches), merge code directly to release on successful completion of PRs.

Current process:

  1. complete Sonar scan on Release1 branch and make it new code reference for project
  2. It works fine, if PR target branch is Release1
  3. Getting error when PR target branch raised set to Release2 or Release3 …, because these branches are not scanned.

Is there any way that SonarQube can detect/register PR target branches automatically whenever PR raised with new target branch? without running sonar scan for Release2, 3 & 4 … ?

Thanks in advance.

No. If you choose to use the reference branch New Code Period, it must be analyzed in SonarQube. SonarQube does not have a mechanism to scan a branch that isn’t checked out.

We have analyzed Reference branch.

my question is for Target branch set in Pull Request.

Thank you.