Invalid new code period

  • ALM used: Bitbucket Cloud
  • CI system used: Bitbucket Pipelines


When analyzing one of our older long-lived branches, I’m getting the following error in Bitbucket Pipelines:
Quality Gate failed: Could not fetch quality gate status: b'{"errors":[{"msg":"Analysis with id \'None\' is not found"}]}'

A closer look at the analysis details gives me this error:
Invalid new code period. '21.03' is not one of: integer > 0, date before current analysis j, \"previous_version\", or version string that exists in the project.

The new code definition is set to the version 21.03, and this version exists in the project. I’m not sure why I’m getting this error, claiming that the version string does not exist?

This happens when doing analysis on our 21.02 branch (one version earlier), and I’m getting the message in SonarCloud that I should set a new code definition for this long-lived branch. However, It seems that I can only set a new code definition for the whole project, and not for a single long-lived branch. The new code definiton (project-wide) has already been set to 21.03.

I realise that the idea of setting a new code definition on a version that’s more recent than the current version is not correct. Is it possible that I’m just missing where I can set a new code definition for a specific long-lived branch?

Any help would be welcome!

Welcome to the community!

The version exists in a different long-lived branch of the project. In the old long-lived branch where you haven’t set a new code period, the value of the main branch is inherited. But if that version did not exist in the old branch, then it’s invalid, and that’s why you get a failure.

Indeed, this seems to be a missing feature, and missing documentation to me. I don’t see a way to set the new code period for a long-lived branch using the UI, but you can do this using the Web API methods api/project_analyses/search and api/project_analyses/set_baseline, documented here.

Step 1: find an analysis of the old long-lived branch that you would like to set as the baseline of the New Code Period, for example with this curl:

curl -u"$SONAR_TOKEN:" "$projectKey&branch=$branch"

Step 2: In the output of step 1, find a suitable analysis object in the "analyses": [ ... ] array, to pick its key value to use as the baseline:

curl -X POST -u"$SONAR_TOKEN:" "$projectKey&branch=$branch&analysis=$key"

I hope this helps!