Mercurial > hg
annotate contrib/cleanup-pipeline.sh @ 52293:77b38c86915d
ci: add a small script one can run to purge older pipeline
We have over ten thousands old pipeline that take a huge space and that I
suspect to be the source of some slowdown in merge request.
However it seems that the only way to clear them is manually and through the
API, so lets do it.
The script was run today.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Tue, 12 Nov 2024 12:45:23 +0100 |
parents | |
children |
rev | line source |
---|---|
52293
77b38c86915d
ci: add a small script one can run to purge older pipeline
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
1 #!/bin/bash |
77b38c86915d
ci: add a small script one can run to purge older pipeline
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
2 # A small script to cleanup old CI-pipeline that accumulate over time |
77b38c86915d
ci: add a small script one can run to purge older pipeline
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
3 |
77b38c86915d
ci: add a small script one can run to purge older pipeline
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
4 |
77b38c86915d
ci: add a small script one can run to purge older pipeline
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
5 d="`date -d '-1 month' --iso-8601`T00:00:00Z" |
77b38c86915d
ci: add a small script one can run to purge older pipeline
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
6 |
77b38c86915d
ci: add a small script one can run to purge older pipeline
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
7 PROJECT_ID=22 |
77b38c86915d
ci: add a small script one can run to purge older pipeline
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
8 |
77b38c86915d
ci: add a small script one can run to purge older pipeline
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
9 token=$1 |
77b38c86915d
ci: add a small script one can run to purge older pipeline
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
10 |
77b38c86915d
ci: add a small script one can run to purge older pipeline
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
11 if [ -z $token ]; then |
77b38c86915d
ci: add a small script one can run to purge older pipeline
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
12 echo "USAGE: $0 GITLAB_TOKEN" >&2 |
77b38c86915d
ci: add a small script one can run to purge older pipeline
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
13 exit 64 |
77b38c86915d
ci: add a small script one can run to purge older pipeline
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
14 fi |
77b38c86915d
ci: add a small script one can run to purge older pipeline
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
15 |
77b38c86915d
ci: add a small script one can run to purge older pipeline
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
16 get_ids() { |
77b38c86915d
ci: add a small script one can run to purge older pipeline
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
17 curl --silent "https://foss.heptapod.net/api/v4/projects/$PROJECT_ID/pipelines?updated_before=$d&per_page=100" | python3 -m json.tool | grep -E '"\bid": ([0-9]+),' | grep -oE '[0-9]+' |
77b38c86915d
ci: add a small script one can run to purge older pipeline
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
18 } |
77b38c86915d
ci: add a small script one can run to purge older pipeline
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
19 |
77b38c86915d
ci: add a small script one can run to purge older pipeline
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
20 ids=`get_ids` |
77b38c86915d
ci: add a small script one can run to purge older pipeline
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
21 while [ -n "$ids" ]; do |
77b38c86915d
ci: add a small script one can run to purge older pipeline
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
22 echo '#########' |
77b38c86915d
ci: add a small script one can run to purge older pipeline
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
23 for pipeline_id in $ids; do |
77b38c86915d
ci: add a small script one can run to purge older pipeline
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
24 echo "deleting pipeline #$pipeline_id" |
77b38c86915d
ci: add a small script one can run to purge older pipeline
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
25 url="https://foss.heptapod.net/api/v4/projects/$PROJECT_ID/pipelines/$pipeline_id" |
77b38c86915d
ci: add a small script one can run to purge older pipeline
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
26 echo $url |
77b38c86915d
ci: add a small script one can run to purge older pipeline
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
27 curl \ |
77b38c86915d
ci: add a small script one can run to purge older pipeline
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
28 --header "PRIVATE-TOKEN: $token"\ |
77b38c86915d
ci: add a small script one can run to purge older pipeline
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
29 --request "DELETE"\ |
77b38c86915d
ci: add a small script one can run to purge older pipeline
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
30 $url |
77b38c86915d
ci: add a small script one can run to purge older pipeline
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
31 done |
77b38c86915d
ci: add a small script one can run to purge older pipeline
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
32 ids=`get_ids` |
77b38c86915d
ci: add a small script one can run to purge older pipeline
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
33 if [ -n "$ids" ]; then |
77b38c86915d
ci: add a small script one can run to purge older pipeline
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
34 sleep 1 |
77b38c86915d
ci: add a small script one can run to purge older pipeline
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
35 fi |
77b38c86915d
ci: add a small script one can run to purge older pipeline
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
36 done |