How to get project_status overall instead of period?

Must-share information:

  • SonarQube 8.5.1
  • Want to have an report from overall to projects related to the quality gate
  • Tried:
    ** qualitygates/project_status but only got the periodIndex=1 with periodTime = 14 days
    ** project_badges/measure doesn’t work for us, because the projects are private
    ** project_analyses/search?category=QUALITY_GATE content is empty
    ** measures/component doesn’t deliver the Quality Gate status

How can I get an overall report, like the overview in Sonarqube? But not for the period of time/new code.

Thank you for your answer in advance.

Best, Rene

Hey there.

A SonarQube project has a single Quality Gate.

This is the overall Quality Gate (the one you see in the UI). It is simply also telling you what the New Code Period is, as that will affect the metrics prefixed with new_*

Take a look at any project you query GET api/qualitygates/project_status for, it will match the Quality Gate you see in the overview of a SonarQube project. :slight_smile:

Thank you for your quick response and your answer.

Maybe I did something wrong, but for me it doesn’t match.

https://sonarqubeadress/api/qualitygates/project_status?projectKey=myprojectkey

returns for me:

    {
    "projectStatus": {
        "status": "OK",
        "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": "OK",
                "metricKey": "new_maintainability_rating",
                "comparator": "GT",
                "periodIndex": 1,
                "errorThreshold": "1",
                "actualValue": "1"
            },
            {
                "status": "OK",
                "metricKey": "new_duplicated_lines_density",
                "comparator": "GT",
                "periodIndex": 1,
                "errorThreshold": "3",
                "actualValue": "0.0"
            }
        ],
        "periods": [
            {
                "index": 1,
                "mode": "NUMBER_OF_DAYS",
                "date": "2021-04-06T11:34:04+0000",
                "parameter": "14"
            }
        ],
        "ignoredConditions": false,
        "period": {
            "mode": "NUMBER_OF_DAYS",
            "date": "2021-04-06T11:34:04+0000",
            "parameter": "14"
        }
    }
}

But the overview shows:

Can you give me any advice, what I could do wrong here? :thinking:

Thanks in advance.

Best,
Rene

Hey there.

The information on your project dashboard and your Quality Gate are two different things – there may be measures in your Quality Gate that don’t appear in your project dashboard, and information in your project dashboard that doesn’t affect your Quality Gate.

Individual measures (bugs, new_bugs, code_smells, 'sqale_rating, coverage, alert_status` (which is the Quality Gate) etc.) can be queried using GET api/measures/component. These keys can be found in the documentation on Metric Definitions.

As an example:

// 20210421094844
// https://next.sonarqube.com/sonarqube/api/measures/component?component=org.sonarsource.javascript%3Ajavascript&metricKeys=coverage,bugs,new_bugs,alert_status

{
  "component": {
    "key": "org.sonarsource.javascript:javascript",
    "name": "SonarJS",
    "description": "SonarQube JavaScript/TypeScript Analyzer",
    "qualifier": "TRK",
    "measures": [
      {
        "metric": "new_bugs",
        "periods": [
          {
            "index": 1,
            "value": "0",
            "bestValue": true
          }
        ],
        "period": {
          "index": 1,
          "value": "0",
          "bestValue": true
        }
      },
      {
        "metric": "bugs",
        "value": "5",
        "bestValue": false
      },
      {
        "metric": "alert_status",
        "value": "OK"
      },
      {
        "metric": "coverage",
        "value": "95.8",
        "bestValue": false
      }
    ]
  }
}

Thank you for your answer and then sorry for mixing then the wrong terms.
Do I understand it then correctly, that the four values “Reliability”, “Security”, “Security Review” and “Maintainability” are in no feed for the overall status as single values?
Maybe I mixed some things up in the beginning. :grimacing: My fault. Sorry for that.

So my goal is, I want to have the four measurements Reliability, Security, Security Review and Maintainability as a value (like the badges - but badges are not possible for us, because of the missing private project support) in a feed for overall (and new code). Maybe I got the wrong feed, before :wink:

**Okay, sorry. Found it. **

squale_rating means Maintainability-Rating
The other ones are reliability_rating, security_rating and security_review_rating

Best,
Rene

p.s.: Offtopic, but important. Happy Birthday to you :wink:

Thanks. :slight_smile:

So all good then? :smiley:

Yes, thank you :slight_smile:

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