Deleting pipelines in Gitlab 11.6

Deleting pipelines in Gitlab 11.6


You run it as ‘python -t token -u url -g group -p project’ and it will list all the pipeline id’s. You can then run it with “-d ‘*'” to delete all of them, or “-d #,#,#…” to delete specific ones. You’ll likely want ‘pip install python-gitlab’ first.


#!/usr/bin/env python3
import gitlab
import argparse
import os
import requests
import sys

parser = argparse.ArgumentParser()

args = parser.parse_args()

if args.delete:
    args.delete = args.delete.split(',')

gl = gitlab.Gitlab(args.url, args.token)

def find_group(gl, group):
    groups = gl.groups.list()
    for g in groups:
        if == group:
            return g
    return None

def find_subgroup(gl, group, subgroup):
    subgroups = group.subgroups.list()
    for sg in subgroups:
        if == subgroup:
            return sg;
    return None

def find_project(gl, group, project_with_subgroup):
    pws = project_with_subgroup.split('/')
    if len(pws) == 2:
        project = pws[1]
        group = gl.groups.get(, lazy=True)
        project = pws[0]
    projects = group.projects.list()
    for p in projects:
        if == project:
            return p
    return None

group = find_group(gl,
gproject = find_project(gl, group, args.project)
if not gproject:

project = gl.projects.get(
pipelines = project.pipelines.list()
for pid in pipelines:
    pl = project.pipelines.get(


7 Comments on “Deleting pipelines in Gitlab 11.6



    Thanks so much!

  2. Traceback (most recent call last):
    File “./”, line 9, in
    NameError: name ‘url’ is not defined




      • on the first, i had not thought of that


Leave a Reply
