Skip to content

cegape/gitlab-pipeline-cleaner

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GitLab Pipeline Cleaner

A Python CLI tool to delete all CI/CD pipelines for a specific branch of a GitLab project. Useful for cleaning up pipeline history after merging or deleting feature branches.

Features

  • Branch-targeted deletion — Delete all pipelines for a specific branch
  • Before/after comparison — Displays pipeline list before and after deletion
  • Interactive confirmation — Requires typing YES before any deletion
  • Pagination support — Handles projects with hundreds of pipelines
  • Self-hosted support — Works with gitlab.com and self-hosted instances

Project Structure

gitlab-pipeline-cleaner/
├── app/
│   ├── gitlab_client.py            # Shared GitLab API client
│   └── clean_branch_pipelines.py   # Delete pipelines for a branch
├── config/
│   └── settings.py
├── .env.example                    # Environment variables template
├── requirements.txt
├── LICENSE
└── README.md

Prerequisites

  • Python 3.8+
  • A GitLab instance (gitlab.com or self-hosted)
  • A GitLab Personal Access Token with api scope

Installation

git clone https://github.com/cegape/gitlab-pipeline-cleaner.git
cd gitlab-pipeline-cleaner
pip install -r requirements.txt

Configuration

cp .env.example .env

Edit .env:

GITLAB_BASE_URL=https://gitlab.com
GITLAB_TOKEN=your-personal-access-token

Usage

Delete all pipelines for a branch:

python app/clean_branch_pipelines.py --project-id 12345 --branch feature/my-branch

The tool will:

  1. List all pipelines for the branch
  2. Ask you to type YES to confirm
  3. Delete all pipelines one by one
  4. Show remaining pipelines after deletion

Finding your project ID

Your project ID is visible on the GitLab project page (under the project name) or via:

# Using GitLab API
curl --header "PRIVATE-TOKEN: your-token" "https://gitlab.com/api/v4/projects?search=my-project"

Safety

Guard Description
Interactive confirmation Requires typing YES before any deletion
Before/after display Shows pipeline list before and after to verify results
Branch-scoped Only affects pipelines for the specified branch

License

This project is licensed under the MIT License.

About

Python CLI tool to delete all CI/CD pipelines for a specific branch of a GitLab project

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages