SonarQube API - rating issue

Must-share information (formatted with Markdown):

  • which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)
  • what are you trying to achieve
  • what have you tried so far to achieve this

Hi Everybody,

I have SonarQube 8.9 and want to use the API to create Quality gates.

It works perfectly for those whose operator is greater than or less than (GT / LT).
For instance:
curl -X POST --insecure -u toooookeeeen: Code Quality and Code Security | SonarQube -d “gateName=theNAME” -d “metric=reliability_rating” -d “op=LT” -d “error=33”

But if i want to create a condition requiring ratings, such as A or B or C, it fails:
curl -X POST --insecure -u toooookeeeen: Code Quality and Code Security | SonarQube -d “gateName=theNAME” -d “metric=reliability_rating” -d “op=LT” -d “error=A”

Is it possible to create conditions that ask for rating? If yes, could you please provide what should be specified as values for “error” “op” ?

This command produces the following error message:
curl -X POST --insecure -u toooookeeeen: Code Quality and Code Security | SonarQube -d “gateName=theNAME” -d “metric=reliability_rating” -d “op=LT” -d “error=0.5”

error: {“msg”:“Operator LT is not allowed for this metric.”},{“msg”:“Invalid value \u00270.5\u0027 for metric \u0027Reliability Rating\u0027”},{“msg”:“\u00270.5\u0027 is not a valid rating”}

Thanks in advance for your valuable assistance.

Hey there.

The valid values for ratings are 1, 2, 3, 4, AND 5 – which correspond to A, B, C, D, and E respectively.

You may find this guide useful as you continue to explore the Web API.

Thank you very much @Colin

Just for those who might be stuck with the same issue:

-d “op=GT” -d “error=1” => translates to worse than A

Sidenote: LT cannot be used with ratings (as far as i tested)

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