This is a simple java cli program to remove old SonarQube projects, to keep the total number of lines of code below that allowed by the license.
Prerequisite: java should be installed and on your PATH.
Download sonarqube-cleanup-cli-x.y.zip
ZIP file from releases (or SNAPSHOT from packages) and extract it.
Depending your environment system, run sonarqube-cleanup-cli.bat
(Windows) or sonarqube-cleanup-cli.sh
(Linux) with options.
At min sonarqube-cleanup-cli.[sh|bat] -h http://sonarqube.company.com -l adminUser -p foobar
Options:
usage: sonarqube-cleanup-cli
-h,--hostUrl <arg> The SonarQube server URL (or sysenv 'SONAR_HOST_URL').
-l,--login <arg> The login or authentication token of a SonarQube user with admin permission (or sysenv 'SONAR_LOGIN').
-p,--password <arg> The password that goes with the login username. This should be left blank if an authentication token is being used (or sysenv 'SONAR_PASSWORD').
-d,--dryRun Dry run mode, no projects will be deleted (default: false ; or sysenv 'SONAR_CLEANUP_DRY_RUN').
-y,--yes Assume projects deletion without confirmation (default: false ; or sysenv 'SONAR_CLEANUP_YES').
-t,--thresholdCoeff <arg> The multiplicative coefficient on threshold to calculate LoC to retrieve (default: 2 ; or sysenv 'SONAR_CLEANUP_THRESHOLD_COEFF').
-n,--numberLocAdd <arg> The number of LoC in addition to retrieve (default: 0 ; or sysenv 'SONAR_CLEANUP_NUMBER_LOC_ADD').
The goal of this program is to delete old SonarQube projects, before the total lines of code authorized by license is reached.
When the threshold is reached (~6% of total LoC by default), a email is sent to administrators.
Two options can be configured to customize behavior, depends the needs ; mainly manual or batch/cron/daily execution.
- thresholdCoeff : This is the threshold multiplicator coefficient, to calculate the number of lines of code to retrieve in projects deletion ; useful when you want execute this program manually on SonarQube email reception
- numberLocAdd : This is the number of line to retrieve in projects deletion, in addition of threshold multiplicator coefficient ; useful when you want execute this program by cron
The combination of both could be done. Think to configure the threshold in http://sonarqube.company.com/admin/extension/license/app
with your needs.
Sample: Your license is 100 millions LoC and you want 1 million of limit (for new big project), but keep the email if limit prior to one hundred thousand (in case of problem, if cron program is not correctly executed):
- Configure your SonarQube threshold to 100000.
- Configure numberLocAdd option to 800000 and let thresholdCoeff to 2 (default value):
100000 x 2 + 800000 = 1000000
SonarQube v6.2, due to api/components/search_projects usage.
This project is using Maven as integration tool.
For development/SNAPSHOT build, use:
mvn package
For release build, use (GitHub credentials specially required on command line if 2FA used):
git reset --hard origin/master
git branch -m next-version
mvn -B clean release:clean release:prepare -Dusername=yourGitHubLogin -Dpassword=yourGitHubToken
After that, you would have to create pull-request from next-version
branch and rebase it on master for next version development.