之前在 /admin/application_settings/ci_cd
中设置了 artifacts 的过期时间为10个小时
本以为 gitlab 会自动清除 artifacts,今天在一个项目的 Settings - Usage Quotas 中查看发现 artifacts 竟然占用了近100GB空间
网上查了一下才知道原来是没有去选下面这个选项引起的,详见 https://stackoverflow.com/a/77349594/5989202
Keep the latest artifacts for all jobs in the latest successful pipelines
请问现在如何删除这近100G的artifacts? 通过 /dev/xxx/-/artifacts
的 UI 界面一次只能删除20个
在这篇博文 Clean up GitLab CI Build artifacts 中找到了解决方法,通过 gitlab cli glab
可以删除以前所有的 ci pipeline
安装 glab
curl -sSL "https://raw.githubusercontent.com/upciti/wakemeops/main/assets/install_repository" | sudo bash
sudo apt install glab
给 glab 授权,通过 access token 授权
glab auth login
通过下面的命令删除10小时之前的所有 ci pipline
screen
glab ci delete --older-than 10h --paginate --per-page 200
如果要删除的 pipeline 不是巨多,删除过程中控制台会有输出
✓ Pipeline #32619 deleted successfully.
✓ Pipeline #32618 deleted successfully.
✓ Pipeline #32617 deleted successfully.
✓ Pipeline #32613 deleted successfully.
✓ Pipeline #32612 deleted successfully.
...
但我们这里 pipeline 实在太多了,一次命令删除10小时之前的所有 pipline,命令发出后长时间无反应,只能分拆删除
glab ci delete --older-than 36000h --paginate --per-page 200
glab ci delete --older-than 18000h --paginate --per-page 200
glab ci delete --older-than 9000h --paginate --per-page 200
glab ci delete --older-than 3000h --paginate --per-page 200
glab ci delete --older-than 1000h --paginate --per-page 200
glab ci delete --older-than 10h --paginate --per-page 200
注:要本地签出所要删除 ci pipeline 的项目的仓库,在仓库目录中运行上面的 glab ci delete
命令,不然会报错
fatal: not a git repository (or any of the parent directories): .git
git: exit status 128
要删除的 pipline 有7万多个