Skip to content
This repository was archived by the owner on Mar 27, 2023. It is now read-only.

Commit 4de2e9d

Browse files
committed
add script for removing old pipelines from GitLab [skip ci]
1 parent 5b54397 commit 4de2e9d

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

delete_pipelines.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# this script removes old GitLab CI pipelines
2+
# there is no option to bulk delete pipelines
3+
4+
if [[ -z "${PROJECT_ID}" ]]; then
5+
echo "Please set a PROJECT_ID environment variable."
6+
exit 1;
7+
fi
8+
9+
if [[ -z "${GITLAB_TOKEN}" ]]; then
10+
echo "Please set a GITLAB_TOKEN environment variable."
11+
exit 1;
12+
fi
13+
14+
15+
16+
BASE_URL="https://gitlab.com/api/v4/projects/$PROJECT_ID/"
17+
PIPELINES_URL="${BASE_URL}pipelines?private_token=$GITLAB_TOKEN&per_page=10000"
18+
19+
20+
echo $PIPELINES_URL
21+
echo "Fetching pipeline ids"
22+
curl $PIPELINES_URL | jq -r '.[].id' > /tmp/ids.txt
23+
24+
echo "Deleting pipelines..."
25+
26+
while read l; do
27+
echo "Deleting $l";
28+
echo $l;
29+
sleep 1;
30+
output=$(curl --header "PRIVATE-TOKEN: $GITLAB_TOKEN" --request "DELETE" "${BASE_URL}pipelines/$l" | echo $1);
31+
echo $output
32+
echo "Deleted pipeline $l"
33+
done < /tmp/ids.txt

0 commit comments

Comments
 (0)