Get all quality gate information for all projects through sonarqube api (version 8.4.2) - sonarqube

I have list of projects in my sonarqube dashboard, how can I get quality information like code coverage, code smell, vulnerability, and other details of all the projects in a single api call (sonarqube web api) ?
Referred web-api documentaion (https://next.sonarqube.com/sonarqube/web_api/), but not able to get much help from it.

The following is a short excerpt from code that gets some metrics from a scan after it is completed:
"curl -s -X GET -u ${authString} \'${sonarProps['sonar.host.url']}/api/measures/component?" +
"metricKeys=coverage,duplicated_lines_density" +
"&component=${sonarQubeProjectName}&branch=${branchName}\'"
The syntax of the property references are unimportant for your question. Notice the list of "metricKeys" being supplied.

Related

How to get SonarQube Issues Report via API

Is there a way to get an issues report by querying the SonarQube web API?
With previous versions of SonarQube, I was able to generate an HTML report after each build but this feature looks like it's been deprecated in newer installments.
At the moment, I'm trying this bit of code
curl -u foo:bar https://sonar.example.com/api/issues/search?pageSize=100&componentKeys=my-app&metricKeys=violations,ncloc,line
But it errors with {"errors":[{"msg":"The 'component' parameter is missing"}]
Ideally, what I'm after is to just get the lines of code, the number of bugs, vulnerabilities, and Code smells in each run/scan.
Something like this
But through querying the API after each analysis.
Is this possible, please?
Had the same issue. The problem is that there is something wrong with the CURL command and you need to specify the full url as string using quotes.
Your case would be:
curl -u foo:bar "https://sonar.example.com/api/measures/search?pageSize=100&componentKeys=my-app&metricKeys=ncloc,violations,complexity"
This is an example with measures. Be sure to check the required parameters.

OpenTest Reporting Library

I am currently seeking information around the available reporting capabilities for OpenTest. I would need information regarding the following:
Portability of reports/logging - can these results be published in various formats
Granularity of reports/logging - is there a way of getting very detailed in what is reported on and/or strategies to ensure that enough information is logged to allow for debugging of automated tests and System Under Test(SUT)
Screenshots - is there current functionality to allow for screenshots to be taken and published/posted to external systems?
Portability of reports/logging
You can obtain the test session results by using the API, either in JSON format (which contains a lot of detail) or the JUnit XML format:
http://localhost:3000/api/session/<SESSION_ID>?format=json
http://localhost:3000/api/session/<SESSION_ID>?format=junit
The detailed log of the test session can be retrieved in: JSON or human-readable format:
http://localhost:3000/api/session/<SESSION_ID>/log?format=json
http://localhost:3000/api/session/<SESSION_ID>/log?format=pretty
Granularity of reports/logging
The test results in JSON format will tell you everything you need to know about the pass/fail status for each test and each individual test action within a test, arguments that were used for test actions, the name of the screenshot captured for each test action, execution times and many other useful information.
When you want to troubleshoot a failed test, most of the time you'll need the detailed log information, which can be retrieved using the APIs I mentioned above. Aside from the log information generated by OpenTest itself, you can always log additional information that is specific to your application or test scenario using the $log JavaScript API.
Screenshots
Screenshots are automatically captured for Web and UI tests, whenever a test action fails. If you need to capture additional screenshots during your test, you can do so using the TakeScreenshot keyword for either Web testing or mobile testing. You can also capture a screenshot after any test action by using the $screenshot global test action argument:
- description: Click product 1 and capture a screenshot
action: org.getopentest.selenium.Click
args:
locator: { id: product1 }
$screenshot: true
You can download screenshots using this API:
https://localhost:3000/api/screenshot/SID1554380072_WEB_T05_SG01_ST01_after_03.png
SID1554380072_WEB_T05_SG01_ST01_after_03.png is the name of the screenshot file, which you can find in the test execution results in JSON format.
Integrating with custom reporting solutions
At some point you will need to integrate with a dedicated reporting product that can give you all the nice features that OpenTest is not be able to provide out-of-the-box. This is possible to do using the APIs I described. In order to notify interested parties of the current status of test sessions, OpenTest also provides a WebSocket API. You can use that to be notified when a test session has finished, then you can extract all the information you need via APIs. You can find a Java project that does all that here: https://github.com/adrianth/opentest-monitor. This project is intended as a starting point for your own custom integration.

Retrieve Test settings using Rest API from TFS

How can i retrieve Test settings using Rest API from TFS.
The below mentioned URL is the best i can get . but this is for Test result retention setting...... and what i am looking for is regular/ general Test settings.
Can some one please provide a sample URL for it.
Sample URL:- https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/Fabrikam/_apis/test/resultretentionsettings?api-version=2.0-preview"
If you mean the test settings file (See Specifying Test Settings for Visual Studio Tests), then you can get and open the file from web portal to check the settings.
If you mean Test configurations, you can refer to this link for the REST API : Test configurations:
e.g.: To Get a test configuration:
GET https://{instance}/DefaultCollection/{project}/_apis/test/configurations/{configurationId}?api-version={version}
Whatever, all the available test REST APIs are all here: Test Management
UPDATE:
According to your clarification (below answer), you just want to get the specific test run details. You can use below REST API to Get a test run:
GET http://{instance}/DefaultCollection/{project}/_apis/test/runs/{run ID}?api-version={version}
Then you will see all the settings/properties of the specific test run.
No what I really meant for was the "Test Settings" information. In MTM, we can specify the TestSettngs via TestSettings Manager.( See the below image.)
While creating a test run, we need to provide this "Test Settings" information.
Next, coming to REST API, we can create a test run using REST API too.
The below is the API reference url.
https://www.visualstudio.com/en-us/docs/integrate/api/test/overview
Under "Create a Test Run" section, you can see "test settings" under the content type. I wanted to know how to get that information via REST call(
Check see image 2 below)
(I am unable to embed pictures on the site as i have not earned 10 reputation points. please open the links provided below to view the images)

How can i get the metrics from SonarCloud using language filter?

I referred this page as described below and could get some values.
$ curl -v "https://sonarcloud.io/api/measures/component?metricKeys=violations&component=key" | jq
But how can I get these values with language filter?
Querying project-level metrics by language is not possible. As you can see on the description of the /api/measures/component web service, there's no language parameter.
If you are interested in issues in particular (I'm asking because I see that you are trying to query the violations metric), then you should be using the /api/issues/search web service for which you have a language parameter.
Thank you for a comment & answer! It was self resolved.
I tried sonar-scanner with language options like -Dsonar.language=c and after that, accessed the Web API. By doing so, I can get the value of C code.

REST API for getting project last analysis date?

How do I get a project's last analysis time (the one you can see in the dashboard) with the REST API of SonarQube?
I am working with SonarQube 4.5.6, but if it's only available on later versions I'd still be interested in how it is done.
[EDIT] API relevant since SonarQube v6.3: api/project_analyses/search
[EDIT] Relevant API for SonarQube LTS v5.6.x: api/projects?versions=true
And since you mention later versions, since SonarQube 5.2:
api/ce/component : get the pending tasks, in-progress tasks and the last executed task of a given component (usually a project) (documentation)
P.S.: api/components/show can be used to get the component ID from the project key
P.S.2 : here's a real-life example on public SonarQube project. First get the component ID then query the component -> "submittedAt": "2016-03-07T06:04:31+0100" (slight difference with the dashboard value, due to the processing time on the scanner side)
You can use the Resources API : https://nemo.sonarqube.org/api/resources/index?metrics=date&format=json and look at the 'date' field to get the last analysis time.

Resources