Remove all artifact (no expire options)


#1

Hi all,

How do I clean all artefacts (for each test pipeline, without an “expire_in” option) that takes up a lot of space on my personal server?


#2

Looking at the issues page, this appears to be a feature that has been worked on and is waiting for one more approval before being merged:

https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/2560

Until then, you would have to go to the folder on the server and delete it manually


#3

If you have hundreds of builds doing it manually is not practical. You can use the rest api with curl, and your favorite scripting language

#!/bin/sh
project_id=456
token=secret
server=myserver
start_job=2
end_job=8
for job_id in $(seq $start_job $end_job)
do 
   curl --request POST --header "PRIVATE-TOKEN:${token}" "https://${server}/api/v4/projects/${project_id}/jobs/${job_id}/erase"
done


#4

Thanks for this snippet. I tried it out and got a tonne of {"error": "404 not found"}. I’m hoping that’s from jobs which didn’t have artifacts.


#5

After a little poking, I found that this snippet worked for me on macOS

#!/bin/bash
project_id="0000000"
token="teenagemutantninjaturtles"
server="gitlab.com"
start_job=30592507
end_job=30626126

for job_id in $(jot - $start_job $end_job)
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

#6

I’ve made another version (in bash) the explicitly list your own jobs (useful if you use Gitlab-CI SaaS) using JavaScript browser console.

http://blog.fgribreau.com/2018/01/remove-gitlab-ci-artifacts-in-batch.html