-
Which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)
SonarQube Enterprise Edition - v 10.5 / Helm deployed -
What are you trying to achieve
Need to integrate SonarQube with an internal CI system. Our CI system creates pipelines that need to associated with a specific analysis (analysisId
in Sonar). There is currently no API that fetches the analysis report (not the QualityGate information) by analysisId or by analysis event (e.g.,VERSION
). -
What have you tried so far to achieve this
- Attempt #1 - Use webhook to retrieve task info, fetch analysisId using ce API and then the analysis report using analysisId. NOTE: I need the analysis report data. Webhook only has
qualityGate
payload.
curl --request GET \ --url 'https://sonar.xyz.com/api/ce/task?id=<taskId from webhook>' \ --header 'Authorization: <auth>`
# Response
{
"task": {
"id": "<task Id>",
"type": "REPORT",
"componentId": "14370493-591d-4e12-969b-f5a18fa06b49",
"componentKey": "<component key>",
"componentName": "<component name>",
"componentQualifier": "TRK",
"analysisId": "486aa640-dff2-422c-9fc6-335f972810e2",
"status": "SUCCESS",
This is however a dead end as there is no API to fetch analysis report using the analysisId
- Attempt #2 - Use project analyses summary API
curl --request GET \
--url 'https://sonar.xyz.com/api/project_analyses/search?project=<project>' \
--header 'Authorization: <>'
# Response
"analyses": [
{
"key": "b4012fb0-2233-446b-ad00-e280444f0224",
"date": "2024-10-23T02:18:34+0300",
"events": [
{
"key": "169a7f11-6d83-4fff-be21-e5315c16ecba",
"category": "VERSION",
"name": "0.0.2"
}
],
"projectVersion": "0.0.2",
"manualNewCodePeriodBaseline": false,
"revision": "df67b970aefb2827e96163a2cb4455fec107a0ba",
"detectedCI": "Jenkins"
},
...]
This API does not return analysis data but it returns the event category that can be used by the client application as an analysis correlation identifier. However, there is no API to fetch a specific analysis by a category value.
- Attempt #3 - Scrape information from
measures/search_history
ormeasures/component
API.
This one was hard to find. I had to scrape Sonar UI and infer that it uses this query to render analysis info:
"https://sonar.xyz.com/api/measures/component?additionalFields=metrics&component=<component>\&metricKeys=alert_status%2Cquality_gate_details%2Cnew_violations%2Caccepted_issues%2Cnew_accepted_issues%2Chigh_impact_accepted_issues%2Cmaintainability_issues%2Creliability_issues%2Csecurity_issues%2Cbugs%2Cnew_bugs%2Creliability_rating%2Cnew_reliability_rating%2Cvulnerabilities%2Cnew_vulnerabilities%2Csecurity_rating%2Cnew_security_rating%2Csecurity_hotspots%2Cnew_security_hotspots%2Csecurity_hotspots_reviewed%2Cnew_security_hotspots_reviewed%2Csecurity_review_rating%2Cnew_security_review_rating%2Ccode_smells%2Cnew_code_smells%2Csqale_rating%2Cnew_maintainability_rating%2Csqale_index%2Cnew_technical_debt%2Ccoverage%2Cnew_coverage%2Clines_to_cover%2Cnew_lines_to_cover%2Ctests%2Cduplicated_lines_density%2Cnew_duplicated_lines_density%2Cduplicated_blocks%2Cncloc%2Cncloc_language_distribution%2Cprojects%2Clines%2Cnew_lines"
and another related API:
curl --request GET \
--url 'https://sonar.xyz.com/api/measures/search_history?component=<component>&metrics=ncloc%2Cduplicated_lines%2Cduplicated_lines_density&p=1&ps=1000' \
--header 'Authorization: Bearer <>'
Both these APIs return analysis measures but they suffer from several constraints:
- Result is indexed by
metric
and not by a specific analysis instance (date
) - Due to metric based index, the response cannot associate analysisId or for that matter a specific analysis event (such as
VERSION
).
Any help is appreciated.