Ostatnio aktywny 1 month ago

GitLab CI

jetsung zrewidował ten Gist 7 months ago. Przejdź do rewizji

1 file changed, 1 insertion, 1 deletion

remove_gitlab_workflow_runs.sh

@@ -3,7 +3,7 @@
3 3 #============================================================
4 4 # File: remove_gitlab_workflow_runs.sh
5 5 # Description: 批量删除 GitLab CI 流水线
6 - # URL: https://s.fx4.cn/
6 + # URL: https://fx4.cn/
7 7 # ORIGIN: https://gist.asfd.cn/jetsung/gitlabci/raw/HEAD/remove_gitlab_workflow_runs.sh
8 8 # Author: Jetsung Chan <[email protected]>
9 9 # Version: 0.1.0

jetsung zrewidował ten Gist 9 months ago. Przejdź do rewizji

1 file changed, 72 insertions

remove_gitlab_workflow_runs.sh(stworzono plik)

@@ -0,0 +1,72 @@
1 + #!/usr/bin/env bash
2 +
3 + #============================================================
4 + # File: remove_gitlab_workflow_runs.sh
5 + # Description: 批量删除 GitLab CI 流水线
6 + # URL: https://s.fx4.cn/
7 + # ORIGIN: https://gist.asfd.cn/jetsung/gitlabci/raw/HEAD/remove_gitlab_workflow_runs.sh
8 + # Author: Jetsung Chan <[email protected]>
9 + # Version: 0.1.0
10 + # CreatedAt: 2025-08-18
11 + # UpdatedAt: 2025-08-18
12 + #============================================================
13 +
14 +
15 + if [[ -n "${DEBUG:-}" ]]; then
16 + set -eux
17 + else
18 + set -euo pipefail
19 + fi
20 +
21 + ORG_NAME=${1:?ORG_NAME is required}
22 + REPO_NAME=${2:?REPO_NAME is required}
23 +
24 + project_path="$ORG_NAME/$REPO_NAME"
25 + encoded_path=$(echo -n "$project_path" | jq -sRr @uri)
26 + url="projects/$encoded_path/pipelines"
27 +
28 + total_deleted=0
29 +
30 + #GITLAB_HOST=""
31 +
32 + delete_pipeline() {
33 + local id=$1
34 + local result=""
35 +
36 + echo "Deleting pipeline ID: $id"
37 + if glab api --method DELETE "$url/$id" --silent; then
38 + result="✅ Deleted pipeline '$id'"
39 + total_deleted=$((total_deleted + 1))
40 + else
41 + result="❌ Failed to delete pipeline '$id'"
42 + echo "$result"
43 + echo "An error occurred while deleting pipeline ID '$id'. Press Enter to exit."
44 + echo "Total pipelines deleted: $total_deleted"
45 + read -n 1 -s -r -p ""
46 + exit 1
47 + fi
48 +
49 + printf "%s\n" "$result"
50 + }
51 +
52 + while true; do
53 + # 获取流水线列表(默认每页20条)
54 + response=$(glab api "$url" --paginate 2>/dev/null || echo "[]")
55 + total_pipelines=$(echo "$response" | jq '. | length')
56 +
57 + if [[ $total_pipelines -eq 0 ]]; then
58 + echo "No more pipelines to delete. Press Enter to exit."
59 + echo "Total pipelines deleted: $total_deleted"
60 + read -n 1 -s -r -p ""
61 + break
62 + fi
63 +
64 + # 使用 process substitution 避免子 shell
65 + while read -r id; do
66 + id="${id//$'\r'/}" # 去掉回车符
67 + delete_pipeline "$id"
68 + done < <(echo "$response" | jq -r '.[].id')
69 +
70 + # 可选:等待几秒再继续循环,避免频繁调用 API
71 + # sleep 2
72 + done
Nowsze Starsze