This repository was archived by the owner on Oct 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremoteRunnersCleanup.sh
More file actions
77 lines (67 loc) · 2.64 KB
/
Copy pathremoteRunnersCleanup.sh
File metadata and controls
77 lines (67 loc) · 2.64 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env bash
SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
source $SCRIPT_DIR/include.sh
delete_runner() {
id=$1
# Disable Runner from Projects
detailed_infos=$(curl --request GET --silent --insecure \
"$GITLAB_URL/api/v4/runners/$id?per_page=100" \
--header "Authorization: Bearer $TOKEN_PERSONAL")
dep_infos=$(echo "$detailed_info" | jq ".projects | [.[] | {id:.id, name:.name}]")
for dep_info in $(echo "$dep_infos" | jq -c ".[]"); do
proj_name=$(echo "$dep_info" | jq .name)
proj_id=$(echo "$dep_info" | jq .id)
echo "Disabling Project $proj_name from Runner $id"
echo $(curl --request DELETE -i --silent --insecure \
"$GITLAB_URL/api/v4/projects/$proj_id/runners/$id" \
--header "Authorization: Bearer $TOKEN_PERSONAL")
done
# Remove Runner
echo -e "Deleting Runner $id"
echo $(curl --request DELETE -i --silent --insecure \
"$GITLAB_URL/api/v4/runners/$id" \
--header "Authorization: Bearer $TOKEN_PERSONAL")
}
# Get runners
runners_resp=$(curl --request GET --silent --insecure \
"$GITLAB_URL/api/v4/runners?per_page=100" \
--header "Authorization: Bearer $TOKEN_PERSONAL")
runners_num=$(echo "$runners_resp" | jq length)
if [[ $runners_num -gt 0 ]]; then
echo "All Runners"
echo "$(echo "$runners_resp" | jq .[] )"
echo "======================"
else
echo "There are no runners"
exit
fi
# Delete offline runners
runners_offline=$(echo "$runners_resp" | jq "[.[] | select(.status==\"offline\")]")
runners_num=$(echo "$runners_offline" | jq length)
if [[ $runners_num -gt 0 ]]; then
echo "Offline Runners"
echo "$(echo "$runners_offline" | jq .[] )"
read -n 1 -s -r -p "Press any key to continue"
echo ""
echo "======================"
runner_ids_offline=$(echo "$runners_offline" | jq ".[] | .id")
for runner_id_offline in $runner_ids_offline; do
echo $(delete_runner $runner_id_offline)
done
else
echo "There were no offline runners"
fi
# Delete unconnected runners
unconnected_runners=$(echo "$runners_resp" | jq "[.[] | select(.status==\"not_connected\",.online==\"null\")]")
unconnected_runners_num=$(echo "$runners_offline" | jq length)
if [[ $runners_num -gt 0 ]]; then
echo "Deleting $unconnected_runners_num Unconnected Runners"
unconnected_runner_ids=$(echo "$unconnected_runners" | jq ".[] | .id")
for unconnected_runner_id in $unconnected_runner_ids; do
echo $(delete_runner $unconnected_runner_id)
done
else
echo "There were no unconnected runners"
fi
read -n 1 -s -r -p "Press any key to continue"
echo ""