3

I'm using SonarQube branch plugin (1.0 (build 507)) and want to retrieve information from branches. My SonarQube version is 6.7.

The SonarQube project (PC_civil-affairs) has three branches, master (main), develop, feature_branch. These are all long-lived branches.

The next calls retrieve information from the master branch https://website.com/sonar/api/project_analyses/search?project=PC_civil-affairs https://website.com/sonar/api/settings/values?component=PC_civil-affairs&keys=sonar.leak.period https://website.com/sonar/api/qualitygates/project_status?projectKey=PC_civil-affairs

How should I adjust the above calls to retrieve the same information from the develop and feature_branch?

agabrys
  • 8,728
  • 3
  • 35
  • 73
dj van kessel
  • 43
  • 2
  • 4

3 Answers3

2

I tested the following solutions on SonarQube 7.1.

project_analyses/search

You have to add the branch parameter. Example:

https://website.com/sonar/api/project_analyses/search?project=PC_civil-affairs&branch=xyz

settings/values

Settings are the same for all branches, so your URL is correct:

https://website.com/sonar/api/settings/values?component=PC_civil-affairs&keys=sonar.leak.period

qualitygates/project_status

Unfortunately, I didn't find any way to get quality gate status.

agabrys
  • 8,728
  • 3
  • 35
  • 73
2

The branches list endpoint exists, with quality gate statuses for each branch: https://website.com/sonar/api/project_branches/list?project=$projectKey. It gives a reponse example like:

  {
    "branches": [
    {
      "name": "feature/foo",
      "isMain": false,
      "type": "SHORT",
      "mergeBranch": "master",
      "status": {
        "qualityGateStatus": "OK",
        "bugs": 1,
        "vulnerabilities": 0,
        "codeSmells": 0
      },
      "analysisDate": "2017-04-03T13:37:00+0100"
    },
    {
      "name": "master",
      "isMain": true,
      "type": "LONG",
      "status": {
        "qualityGateStatus": "ERROR"
      },
      "analysisDate": "2017-04-01T01:15:42+0100"
    }
  ]
}

If you are looking for a specific branch's status, you could pipe it into a tool like jq, and filter with something like:

| jq '.branches | .[] | {name: .name, status: .status.qualityGateStatus} | select(.name=="master") | .status'

And this should return "ERROR" for the master branch status.

ChrisM
  • 167
  • 1
  • 5
  • 12
0

qualitygates/project_status

You can get the quality gate status of your branch when you use the following URL replacing MyBranch with your branch name:

https://website.com/sonar/api/qualitygates/project_status?branch=MyBranch&projectKey=PC_civil-affairs
bomtom
  • 85
  • 1
  • 6