How to Clean Up GitLab Artifacts

Ben Lobaugh
2 min readOct 27, 2022
Photo by Pankaj Patel on Unsplash

If you are running into GitLab storage quota limits there is a high likelihood that the usage is coming from job artifacts. These artifacts contain information about the job itself, such as the files an application built, code scan results, etc. In my experience, there is usually no need to keep the old job runs past a certain age. I typically like to keep around a month of job runs.

Enough about me, you came here to learn how to clean up old GitLab job artifacts!

The following is a script that has been adapted from a forum post at https://forum.gitlab.com/t/remove-all-artifact-no-expire-options/9274. In that thread, scripts in several languages are presented. My preferred scripting language is bash. The script there needed some minor tweaks to work properly. Here is the fixed version.

A couple of things to note about this script:

  • A project ID and API token must be supplied.
  • Private servers are supported. The default is GitLab’s instance at gitlab.com
  • Verify the `start_page` variable is set correctly. A 1 value means that ALL of the artifacts will be removed. If you wish to preserve recent artifacts, increase the value to the page that contains the artifact where cleanup should begin.

The script is well-documented and I encourage you to read through it completely to understand what it is doing.

--

--

Ben Lobaugh
Ben Lobaugh

Written by Ben Lobaugh

Director of Engineering at Mindsize. 20+ year technology veteran. Providing leadership insights, mentorship, and coaching to new and existing leaders.

Responses (1)