Simbu
Simbu

Reputation: 796

How to poll the quality gate execution status?

I would like to poll the quality gate execution status of my SonarQube 6.3 instance using a REST api call. I went through a few api calls, which did not give me the expected results.

I tried to use these urls:

  1. http://localhost:9000/api/resources
  2. http://localhost:9000/api/components

But I always got this response:

{"errors":[{"msg":"Unknown url : /api/resources"}]}

How can I poll the quality gate execution status via REST?

Upvotes: 1

Views: 2179

Answers (3)

Simbu
Simbu

Reputation: 796

http://localhost:9000/api/project_analyses/search?project=myProjectname&category=QUALITY_GATE

This query returned the status of my quality gate. Here I have mentioned the project name as myProjectname

Upvotes: 0

begarco
begarco

Reputation: 776

In fact there are 5 parts in a correct SonarQube web api url. They can be seen like that domain/api/controller/action?parameters, for example http://localhost:9000/api/components/show?componentKey=blue.

So we have:

  1. domain: which is represented by http://localhost:9000 in the example, it is the address where you can call your SonarQube server
  2. api: which is represented by /api in the example, it is the base path of all web service in SonarQube
  3. controller: which is represented by /components in the example, it represents a pool of web service concerning a given theme (issues, profiles, components, etc.)
  4. action: which is represented by /show in the example, it is a unit action that you can perform through the web service, for example: show, search, list, backup, delete, etc.
  5. parameters: which is represented by ?componentKey=bluein the example, they are not always mandatory but often allow you to specify further information to get more precise results

What you have forgotten here is at means to specify an action.

Upvotes: 1

G. Ann - SonarSource Team
G. Ann - SonarSource Team

Reputation: 22824

http://localhost:9000/web_api lists the web service endpoints available on your server and provides documentation for each one. In my copy of 6.3, the documentation for "api/resources" says

Removed since 6.3, please use api/components and api/measures instead

You say you've tried http://localhost:9000/api/components and gotten an error. That's because there's not actually a web service there. You'll have to add the qualifier for the service you want, such as /api/components/search, as described in the docs for that set of services: http://localhost:9000/web_api/api/components

Upvotes: 3

Related Questions