"The scanner failed to compute New Code"

We’re using SonarQube Developer Edition 8.4.1 and SonarScanner
I’ve tried to change the “New Code” Analysis to point to reference Branch “Develop” (main branch) like documented here: https://docs.sonarqube.org/latest/project-administration/new-code-period/
When an analysis for a Feature Branch is performed, I see the following Error
“The scanner failed to compute New Code. Please check your scanner logs.”

Nevertheless there are no errors in the logs. It only shows up
2020.09.07 23:16:33 INFO ce[AXRq21OECwyxeiLQxQrS][o.s.c.t.s.ComputationStepExecutor] Compute new coverage | status=SUCCESS | time=73ms

“Develop” Branch was configured to use “previous analysis” for new code so there is no error.

Any Ideas?

1 Like

Please check your scanner logs with debug enabled. If you post them, we can also have a look at it.
Most likely, for some reason, the scanner can’t compute the diff between the branch being analyzed and the reference branch using a SCM (git usually).

Within the logs I only see the following Output:

2020.09.09 07:35:38 DEBUG ce[AXRxyoSiGH0ILt3Vk4q0][o.s.c.t.p.p.NewCodePeriodResolver] Resolving new code period by previous version: 8.0.0-SNAPSHOT 2020.09.09 07:35:38 INFO ce[AXRxyoSiGH0ILt3Vk4q0][o.s.c.t.s.ComputationStepExecutor] Load new code period | status=SUCCESS | time=44ms

Here is my “New Code” Configuration:

And here is the displayed Error Message:

What irritates is the Message “This branch is configured to use itself as reference branch” which is (as you can see in the screens above) not correct.

I just had a look at the scanner logs (not the sonarqube_ce.log as above) and found the following error:
[2020-09-09T09:25:42.851Z] INFO: Computing New Code since fork with 'develop' [2020-09-09T09:25:42.851Z] WARN: Failed to detect fork date. No New Code will be computed.

Seems that the problem occurs with the SonarQube Scanner and not with SonarQube.

I use Jenkins Multibranch Pipelines to run SonarQube Scanner, which only retrieves the affected branch, so maybe this is the problem.

As far as “edit” is not working anymore here an Update about the Logs when running SonarScanner with “–debug” parameter:

[2020-09-10T12:31:34.743Z] 12:31:34.524 INFO: Load New Code definition
[2020-09-10T12:31:34.743Z] 12:31:34.666 DEBUG: GET 200 https://my.sonarqube-instance.com/api/new_code_periods/show.protobuf?project=analyzedproject&branch=minor | time=142ms
[2020-09-10T12:31:34.743Z] 12:31:34.667 INFO: Load New Code definition (done) | time=143ms
[2020-09-10T12:31:34.743Z] 12:31:34.668 INFO: Computing New Code since fork with 'develop'
[2020-09-10T12:31:34.743Z] 12:31:34.668 WARN: Failed to detect fork date. No New Code will be computed.

I’m surprised that the logs in debug don’t show more details about what’s the cause of the problem.
In any case, not having the branch ‘develop’ fetched is definitely a problem. You’ll need to check it out, and also make sure you don’t have a shallow clone.

I’ve retried the Scan without Jenkins Pipeline specifics by just creating a new working copy (git clone) pointing to “default” branch and checking out the desired branch (git checkout).

Same behaviour:

09:46:54.011 INFO: Load New Code definition (done) | time=83ms
09:46:54.012 INFO: Computing New Code since fork with 'default'
09:46:54.012 WARN: Failed to detect fork date. No New Code will be computed.

The analysis on “default” was performed and shows up in SonarQube, I’ve configured ALM Settings in Sonarqube correct (Using Bitbucket Server).

Are there any additional settings I need to configure in sonar-project.properties?

Git config looks the following way:

    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
[remote "origin"]
    url = ssh://git@mybitbucket-instance.com:9000/myproject/myrepo.git
    fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
    remote = origin
    merge = refs/heads/master
[branch "feature/TestNewCodeCalculation"]
    remote = origin
    merge = refs/heads/feature/TestNewCodeCalculation

I use git 2.17.1

Do you have the sonar-scm-git plugin installed (it is installed by default)?

yes, sonar-scm-git-plugin-

Are you passing sonar.scm.disable=true?
Could you post the full debug logs of the scanner?

sonar-project.properties is quite simple:


Sonar Scanner Command is also straightforward:

sonar-scanner -X -Dsonar.branch.name=feature/TestNewCodeCalculation

Communication from SonarQube to Bitbucket works (even Pull Request Decorators work)

Attached you will find the whole Scanner Log with Debug Output. It was taken from a smaller Project with Default Branch “master”. Analysis was taken on my Windows Machine (to exclude Jenkins as possible Problem)

scanner.log (40.3 KB)

You need to upgrade the sonar-scm-git plugin to v1.12.0.2034. In v1.11 the feature wasn’t implemented yet.

Perfect, that solved the Issue.
Nevertheless it seems that SonarQube checks that there is a new Plugin available but the “Download” Button is missing

Well the good news is that the Git and Svn Plugins will no longer be plugins starting in v8.5 - they’ll be part of SonarQube. That will prevent problems like this from happening again.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.