Delete artifacts in gitlab pipelines

    //Go to: https://gitlab.com/profile/personal_access_tokens
    const API_KEY = "-";
    
    //You can find project id inside the "General project settings" tab
    const PROJECT_ID = 268;
    const PROJECT_URL = "https://gitlab.vanenburg.com/api/v4/projects/" + PROJECT_ID + "/"
    
    let jobs = [];
    for(let i = 0, currentJobs = []; i == 0 || currentJobs.length > 0; i++){
        currentJobs = await sendApiRequest(
            PROJECT_URL + "jobs/?per_page=100&page=" + (i + 1)
        ).then(e => e.json());
        jobs = jobs.concat(currentJobs);
    }
    
    //skip jobs without artifacts
    jobs = jobs.filter(e => e.artifacts);
    
    console.log(jobs)
    //keep the latest build.
    jobs.shift();
    
    for(let job of jobs)
        await sendApiRequest(
            PROJECT_URL + "jobs/" + job.id + "/artifacts",
            {method: "DELETE"}
        );
    
    async function sendApiRequest(url, options = {}){
        if(!options.headers)
            options.headers = {};
        options.headers["PRIVATE-TOKEN"] = API_KEY;
    
        return fetch(url, options);
    }