Sonarqube retention policy

Sonarqube version - 7.9.2
We are using Sonarqube Enterprise edition. I need to configure a retention policy in SonarQube to delete the 2 years old reports automatically. And I need to configure, when it is trying to reach the code to 30 million lines, and then to delete the 2 year old reports.

Have gone through the URL - Housekeeping | SonarQube Docs. Will it resolve my issue and how to define for 30 million lines of code. Any plugins available for the same ? Small inputs also would be really helpful. Thanks in advance.

Hey there.

You can use POST api/projects/bulk_delete with the analyzedBefore parameter (documentation linked in the footer of your instance).

Surely you can find some Web API that will return the LoC available (like the internal GET api/editions/show_license) but why not just have it run weekly/monthly? This way it’s consistent when projects will age-out (no surprises just because your LoC jumped up)

Hello Colin,
I’m bit confused, could you please be specific on what you are trying to say ?

Hey @Dinaa

To do any sort of automation with your SonarQube instance (deleting projects not analyzed for 2 years, for example), you’ll need to use Web APIs (the documentation for the Web API is linked in the footer of your instance).

Have you used Web APIs before?

Hello,
I heard and I have not used it earlier. Could you please provide some sample codes so that I can try with it ?
I have checked the web api - POST api/projects/bulk_delete, but this one deletes the complete project. But for me it needs to delete the old reports older for 2 years and if it reaches 30 million lines of code.

Hey there.

I think you have a misunderstanding regarding SonarQube counts Lines of Code. The Lines of Code that count towards your license are the Lines of Code of the most recent analysis of the largest branch of your project. Old analyses have no bearing – but it’s a good idea to clean them up only so that your database doesn’t get too bulky. For this, the housekeeping settings you found (Housekeeping | SonarQube Docs) detail what is possible – but it has no effect on Lines of Code utilization.

Which Web API should we use for deleting the old reports ? As far I have seen, the web API is present for deleting the complete project and not the report.

There is not much use in deleting the old reports – as they have no bearing on your license utilization. What then, would be the goal of programmatically removing old reports outside the normal housekeeping?

Hey Dinaa , I’m trying to implement a similar Retention Policy where I wish to delete all the analysis data and reports older than 12 months but NOT the entire project. Did you find a way out?