Any api that will get activity details to show how many times the quality gate have executed?

Must-share information (formatted with Markdown)

  • Version: SonarQube 9.1
  • Problem Statement: We are trying to find out how many times the quality gate have passed or failed for any project . Is there any such API which will give the quality gate activity details?
  • what have you tried so far to achieve this: We have gone through the api endpoints that are listed for quality gate but unable to get the desired result.

Hi,

Welcome to the community!

What’s recorded is when the Quality Gate status changes, so you could look for those Events in the Activity records, and make guesses about how many analyses were in the previous status. But they would only be guesses because records of old analyses are routinely cleaned out by the housekeeping routines.

 
HTH,
Ann

Hi Ann,

Thank you for your response.

I have gone through the housekeeping routines link and was able to see that the Audit logs will be deleted monthly.
Do we have the exact date when these logs gets deleted is it on first of every month or on last day of month?

Regards,
Priyanka

Hi Priyanka,

There’s not a set date. Housekeeping is run at the end of background task processing for each analysis. When it runs, anything that’s expired (so in this case, Audit logs that are 30d old) will be deleted.

 
HTH,
Ann

Hi Ann,

Is there anyway through which we can take the backup of these analysis and store it somewhere like repos ?

Regards,
Priyanka

Hi Priyanka,

Perhaps you want to edit your housekeeping settings instead?

Could you share what you’re trying to accomplish?

 
Ann

Hi Ann,

We have setup Azure Devops CI/CD pipeline for some of our applications and we are running sonarqube task for these application. We wanted to keep track of how many times the sonar quality gate passed or failed for these applications whenever we run the pipelines.

Regards,
Priyanka

Hi Priyanka,

Since you’re only after Quality Gate status, that should be easy enough to retrieve and store after each analysis. Take a look at the Measures calls in the Web API (on-board docs link in your page footer). I guess you’ll want to add something to the end of your pipeline to do that.

I’m still kinda curious why you want to keep a count though. Would you mind sharing? Because our thinking is that all that really matters is the Quality Gate status when you want to release.

 
Ann

Hi Ann,

We are planning to create a dashboard where we wants to show the KPI’s related to sonarqube. We wanted to show how many times our pipeline has passed or failed because of sonar quality task . In order to create such reports we were looking for the API’s that can give these details.

Regards,
Priyanka.

Hi Priyanka,

Thanks for sharing.

Personally, I question why this is considered a KPI. Even with SonarLint in the IDE, issues can still be raised on full analysis (there are rules we don’t run in SonarLint so as to not impact IDE performance). Even with analysis on PRs, there are sometimes issues that don’t show up until after merge (although I’m failing to remember what at the moment).

Ideally, SonarQube is a tool to help developers stay on track. Mistakes (e.g. a failing Quality Gate) are part of the game and what’s important is how quickly a problem is corrected, not whether there was a problem to start with.

This attitude is what you find reflected in the way SonarQube works: analyses with “events”, such as a change in Quality Gate status, are retained. Analyses with no change just aren’t important enough to be kept, let alone - in our opinion - counted.

 
FWIW,
Ann