My company has been using SonarQube for several years, and there are hundreds of abandoned projects that need to be cleaned up. Manual batch deletion is more cumbersome and prone to accidental deletion. I would like to write two SQL statements to help me clean up some space.
Delete all contents of the project, including the code under the branch, according to the project name.
Delete the entire project or some branches based on the last analysis time used. (for example, branches or main branches that were six months ago from the last analysis time will be deleted)
The sonarqube version I am using is 7.9.4, and the database is PostgreSQL 10.18.
The database and table associations of SonarQube are quite complex, and it’s a bit troublesome for us to write them ourselves.
If you have any suggestions or if someone has done similar things before, please reply to this post.
I noticed that there are several areas in the Configuration/Configuration/General settings/organization that seem to meet some of my requirements, but after modifying the default values, they have not changed.
Where does the ‘this sonar.dbcleaner’ attribute need to be enabled?
We advise people to treat the DB like a black box that you really want to keep your hands out of. (Obligatory Dune reference.)
Instead you should use Administration → Projects → Management to delete these project. You mentioned that “manual batch” deletion was tedious. Were you referring to this page? If so, you should be aware that you can script the calls that page makes.
The best way to master the API is to perform the desired action via the UI and eavesdrop to see which calls the UI made to accomplish the action.
Regarding the setting you found, its for deleting analyses, not projects. And it’s not going to kick in for dormant projects because housekeeping only kicked in during (at the end of) server-side analysis processing. (It’s possible that it needs to be a main branch analysis, but I’m fuzzy on that.)