Clean up gitlab pipelines

I’ve been trying to set up a new repository with a CI in my GitLab environment. During the configuration, I’d created many failed jobs and pipelines. I searched for a solution to delete and remove the failed pipelines from my history. This was only possible for single jobs. This was not a satisfying solution for me. Therefore, I’ve created a small JavaScript snippet.


Go to your pipelines view for example and execute the JavaScript.

Minified version ( Bookmark ):

javascript:let token;function checkToken(){const e="PIPELINEDELETIONTOKEN";if((token=localStorage.getItem(e))||(token=window.prompt("Please input gitlab token for pipeline deletion.",""),localStorage.setItem(e,token)),!token)throw"Missing token to delete pipelines"}function send(e,t,n){var o=new XMLHttpRequest;o.onreadystatechange=function(){4==o.readyState&&200==o.status&&n&&n(o.responseText)},,t),o.setRequestHeader("PRIVATE-TOKEN",token),o.send()}var getCurrentProjectId=()=>document.body.getAttribute("data-project-id");function getShownPipelineIds(){return".pipeline-id")).map(e=>e.innerText.match(/(\d*)$/)).filter(e=>e.length>1).map(e=>e[1])}function deleteShownPipelines(){checkToken();var e=getCurrentProjectId();getShownPipelineIds().forEach(t=>deletePipeline(e,t)),location.reload()}deletePipeline=((e,t)=>send("DELETE",`${location.origin}/api/v4/projects/${e}/pipelines/${t}`)),deleteShownPipelines();

Sadly, this code requires personal access tokens. I was hoping it was working with the already stored session information in the cookies. You can find all here. The snippet will ask for the token and will store it in the local storage.


let token;
function checkToken() {
    token = localStorage.getItem(KEY);
    if (!token) {
        token = window.prompt("Please input gitlab token for pipeline deletion.", "");
        localStorage.setItem(KEY, token);

    if (!token) {
        throw "Missing token to delete pipelines";

function send(verb, url, callback) {
    const xhr = new XMLHttpRequest();
    xhr.onreadystatechange = function()
        if (xhr.readyState == 4 && xhr.status == 200 && callback)
    };, url);
    xhr.setRequestHeader('PRIVATE-TOKEN', token)

const getCurrentProjectId = () => document.body.getAttribute('data-project-id');

function getShownPipelineIds() {
        .map(x => x.innerText.match(/(\d*)$/))
        .filter(x => x.length > 1)
        .map(x => x[1])

const deletePipeline = (projectId, pipelineId) => send('DELETE', `${location.origin}/api/v4/projects/${projectId}/pipelines/${pipelineId}`);
function deleteShownPipelines() {
    const projectId = getCurrentProjectId();
    getShownPipelineIds().forEach(id => deletePipeline(projectId, id));