SonarQube historical analysis

I was reading this post from some time back

Statistics of issues over a time and all projects - #3 by OlivierK

We’d like to do something similar, as in say we have 50K issues at the moment. We’d like to be able to look back month by month to see how we are progressing. But from the answers provided in the linked post, it doesn’t seem like SonarQube is really setup to do this. Its more of a “in the moment” tool. Is this still the case?

Hello @eryan ,

Your post raised a notification to me so let me respond:

But from the answers provided in the linked post, it doesn’t seem like SonarQube is really setup to do this. Its more of a “in the moment” tool. Is this still the case?

Yes an not. Issues details are kind of snapshot moments in the tool but we keep history of metrics (like count of issues, possibly broken down by severity, type etc).
So for instance the GET api/measures/search_history?component=<projectKey>&metrics=ncloc,coverage,blocker_violations,critical_violations,vulnerabilities API call would return the history of project in terms of Nbr of LoC, Code coverage %, blocker and critical issue count and vulnerabilities count.

I chose metrics randomly. GET api/metrics/list would give you the (huge) list of metrics that you can query.

And finally, if you want a readymade (open source contributed, not particularly SonarSource endorsed) tool that would take care of the API calls for you have a look at sonar-tools · PyPI, and specifically the sonar-measures-export tool.

sonar-measures-export -u <SonarQubeURL> -t <token> --history -f measures-history.csv

Would do the trick.

What kind of permissions do you need to run this api call? The API documentation says that

“Requires the following permission: ‘Browse’ on the specified component.”

The project I have selected is marked as PUBLIC. So in theory everyone has Browse permission right?

I am getting the following error:

Invoke-WebRequest : {“errors”:[{“msg”:“Insufficient privileges”}]}

Using the same token I am able to call /api/issues/search