GET api/qualitygates/project_status return previous version instead of last_version

Hello Sonar Family,

  • versions used (SonarQube Version 8.1 (build 31237))
  • error observed:

Web API
api/qualitygates/project_status return
periods

{@{index=1; mode=PREVIOUS_VERSION; date=2020-09-24T05:26:41-0500; parameter=10.10.0.284}}

My last qualitygates verion is 10.10.0.285
I expect get 10.10.0.285 instead of 10.10.0.284

I checked using Powershell (Invoke-WebRequest) and using curl (both return the same result)

It is a bug?
Any idea how to get “mode”: “last_version”

Thank you in advance.

Hello @thomaswojtowicz,

Welcome to the SonarSource community forum.

I think that you are not looking at the right piece of the API response. I could not double check on SonarQube 8.1 (The LTS (Long Term Support) is 7.9, the latest is 8.4) but I am quite confident that the behaviour is the same. api/qualitygates/projects_status return 2 pieces of information:

  • What is the latest quality gate status of the project
  • How the new code period is computed

Something like:

{
   "projectStatus": {
   "status": "ERROR",
   "conditions": [
   {
      "status": "OK",
      "metricKey": "new_reliability_rating",
      "comparator": "GT",
      "periodIndex": 1,
      "errorThreshold": "1",
      "actualValue": "1"
   },
   {
      "status": "OK",
      "metricKey": "new_security_rating",
      "comparator": "GT",
      "periodIndex": 1,
      "errorThreshold": "1",
      "actualValue": "1"
   },
   {
      "status": "ERROR",
      "metricKey": "new_maintainability_rating",
      "comparator": "GT",
      "periodIndex": 1,
      "errorThreshold": "1",
      "actualValue": "2"
   },
   {
      "status": "ERROR",
      "metricKey": "new_coverage",
      "comparator": "LT",
      "periodIndex": 1,
      "errorThreshold": "80",
      "actualValue": "0.0"
   },
   {
      "status": "OK",
      "metricKey": "new_duplicated_lines_density",
      "comparator": "GT",
      "periodIndex": 1,
      "errorThreshold": "3",
      "actualValue": "0.0"
   }
],
"periods": [
   {
      "index": 1,
      "mode": "SPECIFIC_ANALYSIS",
      "date": "2019-10-07T11:29:08+0200",
      "parameter": "AW2ljYhOpSgD31o0eY4H"
   }
],
   "ignoredConditions": false
   }
}

You must be looking at the periods data (that explains how the new code period is computed, most of the time based on previous version
whereas you should look at the projectStatus data that give you the quality gate status and always refer to the last analysis.

Olivier

1 Like

Got it, make sense. Thanks!

You’re welcome. I’m closing the thread then.
Enjoy SonarQube :sonarqube: !