All new projects must now define their new code on SonarCloud to get a Quality Gate

Hello SonarCloud community,

From now on, all new projects have to define their new code to get a Quality Gate. The clean-as-you-code methodology is at the heart of SonarCloud and there is no one definition that can fit perfectly for all projects. So you will be prompted to select the definition that best fits your project right after having created it:

We fully revamped the configuration window for the new code definition to better convey what each option is about:

As a result of these changes, the Quality Gate will not be computed for the first analysis. The focus of our default Quality Gate is on new code only so that it cannot be computed without the definition of new code being available.

Of course, if you are already familiar with the concept you can set up a default value for the new code definition in your organization settings (Organization → Administration → New Code) that will be applied to all new projects.

The SonarCloud :sonarcloud: Team

1 Like

Hi @Martin_Bednorz,
I having some issues with this new change.
I don’t see the option to Set New Code definition on already existing projects.
I have set the organization New Code definition.
Any help would be appreciated.

1 Like

Hello @jcmuddle,

Welcome to the community!

Existing projects were automatically migrated to their previous setting. Before this change, the default value was set to the last 30 days, so I imagine that your existing projects were migrated to that value as well. You can navigate to the configuration page by selecting Administration --> New Code inside your project on SonarCloud.

@Martin_Bednorz but the problem is that in existing projects, they have the status “None” or “Not computed” in the quality portal, causing failures in the gate.

We have a parameter similar to “sonar.leak.period” to use the “Previous version” option. See the script below as I use it before the change.

# Set New Code Period

Write-Host “”

Write-Host “Set New Code Period”

$Date = “previous_version”

$NewCodePeriodPost = $SetKeyURL -f $BuildRepositoryNameURL, “sonar.leak.period”, $Date

Try {

  • $Post = Invoke-RestMethod -Method Post -Uri $NewCodePeriodPost -Headers $Headers*

  • Write-Host " sonar.leak.period: “$Date” done!"*

} catch { Write-Host " sonar.leak.period: “$Date” failed!"}

I didn’t find anything in the official documentation or in the community with the “” Previous version "parameter.

Can you help?

Hi @andressantos10,

We have an on going documentation work about these parameters.

After the new code recent changes, this configuration was modified. Now it is necessary to configure the value and type (sonar.leak.period.type) of the leak period. You can keep the approach you have now for the value (sonar.leak.period), but need also to send the type (you must send both at same request as you can check at the API settings documentation). The types allowed (for the sonar.leak.period.type setting) are: “date”, “version”, “days” and “previous_version”.

Thanks @Alexandre_Holzhey, I’ll test.

1 Like

@Alexandre_Holzhey, I successfully tested this parameter in my sonarcloud setup script. But the documentation goes without this information … lol Thanks for the help. I’m very grateful.

I am happy this solved your problem! We are working about the documentation, thanks for your feedback!

1 Like

Is there a way to change the existing project properties to be “previous_version”?

Yes, as i described in previous answer the types allowed are:

You can do this change using the UI, at project administration option “New Code”. You can also set it for the organization, configuring a default new code setup to be used into new projects only. For existent projects you should change them individually.

@Alexandre_Holzhey
is it a bug that: https://sonarcloud.io/api/settings/values?component=[project] dont list the setting for new code?
Also is it posible you can update web page so it list what the keys are for each setting.
Just like here: