How to configure the Fudge Factor ('sonar.qualitygate.ignoreSmallChanges') using the Rest API?

Hi,

I like to update the setting for the Fudge Factor as described in: Managing your project's quality gate | SonarQube Server | Sonar Documentation

I am trying to set the setting to false

I like to do it through the Rest API, so I can do it for all projects that I am controlling, I cannot set it global for the organization.

First I call:

[GET] https://sonarcloud.io/api/settings/values?component=<project_key>&keys=sonar.qualitygate.ignoreSmallChanges

It returns an empty list, then I set it using:

[POST] https://sonarcloud.io/api/settings/set?component=<project_key>&key=sonar.qualitygate.ignoreSmallChanges&value=false

When I then call Get again then it is returned as false, looks good so far.

But in the UI under the project, the toggle:

is not updated to reflect this. I have also tried to toggle it myself and do a GET but it is like they are not linked, is it not the same?

Thank you

Mikkel

So the only way I have found to do this is as follows (please tell me that I am wrong and there is a better way), using Api v2, since I cannot find a way through v1:

[GET] https://api.sonarcloud.io/projects/projects?keys=project_key
Returns LegacyId

[GET] https://api.sonarcloud.io/quality-gates/settings?resourceId=LegacyId&resourceType=PROJECT
Returns an Id (not sure what it is but used in next call)

[PATCH] https://api.sonarcloud.io/quality-gates/settings/id_from_above
Body: {ignoreSmallChanges: false}

The last 2 is taken from the UI (inspector), not documented, so can I rely on these?

Thanks

Mikkel

Hey @Mikkel,

This setting cannot be set using the API v1 POST ``https://sonarcloud.io/api/settings/set. sonar.qualitygate.ignoreSmallChanges is a legacy setting in SonarQube Cloud (in fact, it’s not documented, most likely you inferred it from its equivalent in SonarQube Server).

As you found, the way the UI does it is by first finding the project key, then finding the project settings resource ID (this is the ID that you were confused about) and then using it to PATCH the quality gates API with the ignoreSmallChanges setting.

The last 2 is taken from the UI (inspector), not documented, so can I rely on these?

Yes, these API v2 endpoints are “internal”, which means they’re not documented and we don’t guarantee stability. The behavior might change without any deprecation notice. That being said, they’re the only way to automate this particular setting, so from this I would deduce:

  • This setting is not meant to be automated/controlled via API.
  • If you really wish to do this, then go ahead, but you have to understand the limitations: breaking changes might happen without notice.