GitLab: Clean Up Pipes

GitLab: Clean Up Pipes
Photo by Ricardo Gomez Angel / Unsplash

If you have multiple projects running numerous builds, your job history will grow, even when you chop off repository branches. Let's discuss a few methods to keep it tidy.

The most obvious and (there should be a rule for this) the least effective way is manual deletion. It takes a few steps to complete such a minute action:

  1. In the navigation pane of your GitLab project, locate the Build/Jobs page and find the job you want to drop.
  2. Click on the Status icon in the first column.
  3. Now you have access to the job instance control. Three icons in the header allow you to delete the job, edit job variables, and restart the instance.
T
  1. As it wasn't hard enough to get there, the system will ask you to confirm your intentions.

When I've jumped through the hoops for the first time, I realize that it may take a few days to delete about two hundred jobs this way. A quick discussion with the local AI led me to the GitLab CLI utility, glab. After a simple installation and configuration, you get a tool that allows you to do magic.

Help Screen for CI/CD Job Deletion

The most useful parameters are:

  • Delete by time (--older-than time-period) allows you to delete any job that is older than the specified time interval.
$ cd ~/my-project-folder/
$ glab ci delete --older-than 48h
  • Delete by state (--status) will delete any job that matches the provided status.
$ glab ci delete --status canceled

Of course, you can combine filters and, for instance, delete all failed jobs older than a week.

As with any automation tool, be cautious with non-reversible changes. I highly recommend starting any mass extermination with a --dry-run argument, before the actual deletion.

And finally, for the hands-free CI/CD pipeline control, you may choose the automated job purging. It's as easy as it sounds:

  • Open your repository settings
  • Locate the CI/CD Settings section
  • Expand the CI/CD group
  • Specify the duration you want to retain your pipeline executions in the Automatic Pipeline Cleanup field.
Save changes to delete any job older than two weeks

To wrap up:

  • Configure automated pipeline cleanup, especially for long-term history (two weeks or more).
  • Use GitLab CLI utility to perform mass pipeline cleanups.
  • Use the GitLab UI to manually delete job instances, especially if you have all time in the world.