我在 gitlab.com 上有一个使用 CI 功能的私有(private)存储库。一些 CI 作业会创建存储的工件文件。我刚刚通过将其添加到 CI 配置中实现了一天后自动删除工件:
expire_in: 1 day
这很好用——但是,旧的工件不会被删除(如预期的那样)。所以我的问题是:
如何删除旧的工件或不会过期的工件? (在 gitlab.com 上,不能直接访问服务器)
最佳答案
您可以使用 GitLab REST API如果您无法直接访问服务器,请从作业中删除工件。这是 sample curl script使用 API:
#!/bin/bash
# project_id, find it here: https://gitlab.com/[organization name]/[repository name]/edit inside the "General project settings" tab
project_id="3034900"
# token, find it here: https://gitlab.com/profile/personal_access_tokens
token="Lifg_azxDyRp8eyNFRfg"
server="gitlab.com"
# go to https://gitlab.com/[organization name]/[repository name]/-/jobs
# then open JavaScript console
# copy/paste => copy(_.uniq($('.ci-status').map((x, e) => /([0-9]+)/.exec(e.href)).toArray()).join(' '))
# press enter, and then copy the result here :
# repeat for every page you want
job_ids=(48875658 48874137 48873496 48872419)
for job_id in ${job_ids[@]};
do
URL="https://$server/api/v4/projects/$project_id/jobs/$job_id/erase"
echo "$URL"
curl --request POST --header "PRIVATE-TOKEN:${token}" "$URL"
echo "\n"
done
关于gitlab-ci - 手动从 CI 中删除工件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42512733/