Mercurial > hg
changeset 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 | 085cc409847d |
children | a3fa37bdb7ec |
files | contrib/cleanup-pipeline.sh |
diffstat | 1 files changed, 36 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/contrib/cleanup-pipeline.sh Tue Nov 12 12:45:23 2024 +0100 @@ -0,0 +1,36 @@ +#!/bin/bash +# A small script to cleanup old CI-pipeline that accumulate over time + + +d="`date -d '-1 month' --iso-8601`T00:00:00Z" + +PROJECT_ID=22 + +token=$1 + +if [ -z $token ]; then + echo "USAGE: $0 GITLAB_TOKEN" >&2 + exit 64 +fi + +get_ids() { + 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]+' +} + +ids=`get_ids` +while [ -n "$ids" ]; do + echo '#########' + for pipeline_id in $ids; do + echo "deleting pipeline #$pipeline_id" + url="https://foss.heptapod.net/api/v4/projects/$PROJECT_ID/pipelines/$pipeline_id" + echo $url + curl \ + --header "PRIVATE-TOKEN: $token"\ + --request "DELETE"\ + $url + done + ids=`get_ids` + if [ -n "$ids" ]; then + sleep 1 + fi +done