Skip to content

Commit d801a13

Browse files
committed
Add doc for #2005
1 parent bcdbd74 commit d801a13

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

doc/sonar-housekeeper.md

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,44 @@
1-
# <a name="sonar-housekeeper">
1+
# sonar-housekeeper
22

33
Deletes obsolete/outdated data from SonarQube:
44
- Projects whose last analysis date (on any branch) is older than a given number of days.
55
- User tokens older than a given number of days
66
- Inactive branches (Branches not analyzed for a given number of days), excepted branches marked as "keep when inactive"
7+
There is a possibility to override the "keep when inactive" regexp if the original SonarQube one was wrong and caused many branches to be kepf
78
- Inactive pull requests (PRs not analyzed for a given number of days)
89

9-
Usage: `sonar-housekeeper [-P <days>] [-B <days>] [-R <days>] [-T <days>] [--mode delete]`
10+
Usage: `sonar-housekeeper [-P <days>] [-B <days>] [-R <days>] [-T <days>] [--keepWhenInactive <regexp] [--mode delete]`
1011

1112
- `-P <days>`: Will search for projects not analyzed since more than `<days>` days.
1213
To avoid deleting too recent projects it is denied to specify less than 90 days
1314
- `-B <days>`: Will search for projects branches not analyzed since more than `<days>` days.
1415
Branches marked as "keep when inactive" are excluded from housekeeping
1516
- `-R <days>`: Will search for pull requests not analyzed since more than `<days>` days
1617
- `-T <days>`: Will search for tokens created since more than `<days>` days
18+
- `--keepWhenInactive <regexp>`: Overrides the SonarQube `sonar.dbcleaner.branchesToKeepWhenInactive` to with another regexp to consider branches to delete
1719
- `--mode delete`: If not specified, `sonar-housekeeper` will only perform a dry run and list projects
1820
branches, pull requests and tokens that would be deleted.
1921
If `--mode delete` is specified objects are actually deleted
2022
- `-h`, `-u`, `-t`, `-o`, `-v`, `-l`, `--httpTimeout`, `--threads`, `--clientCert`: See **sonar-tools** [common parameters](https://github.com/okorach/sonar-tools/blob/master/README.md)
2123

24+
## Examples
2225

23-
:warning: **sonar-tools** 2.7 or higher is required for `sonar-housekeeper` compatibility with SonarQube Server 10
26+
```
27+
export SONAR_HOST_URL=https://sonar.acme-corp.com
28+
export SONAR_TOKEN=squ_XXXXXXYYYYYZZZAAAABBBBCCCDDDEEEFFFGGGGGG
29+
30+
# Deletes all branches that have not been analyzed for 90 days and where the branch name does not match '(main|master|release|develop).*'
31+
sonar-housekeeper -B 90 --keepWhenInactive '(main|master|release|develop).*' --mode delete
32+
33+
# Lists projects that have not been analyzed on any branch or PR in the last 365 days, on SonarQube Cloud
34+
sonar-housekeeper -P 365 -u https://sonarcloud.io -t <token> -o <organization>
35+
36+
# Deletes projects that have not been analyzed on any branch or PR in the last 365 days
37+
sonar-housekeeper -P 365 --mode delete
38+
39+
# Deletes tokens created more than 365 days ago
40+
sonar-housekeeper -T 365 --mode delete
41+
```
2442

2543
## Required Permissions
2644

@@ -41,8 +59,3 @@ To avoid bad mistakes (mistakenly deleting too many projects), the tools will re
4159

4260
### :warning: Database backup
4361
**A database backup should always be taken before executing this script. There is no recovery.**
44-
45-
### Example
46-
```
47-
sonar-housekeeper -u https://sonar.acme-corp.com -t 15ee09df11fb9b8234b7a1f1ac5fce2e4e93d75d
48-
```

0 commit comments

Comments
 (0)