File: cleanup-pipeline.sh

package info (click to toggle)
mercurial 7.0.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 44,824 kB
  • sloc: python: 206,444; ansic: 56,415; tcl: 3,715; sh: 1,797; lisp: 1,483; cpp: 864; makefile: 752; javascript: 649; xml: 36
file content (36 lines) | stat: -rwxr-xr-x 876 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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