Although the answers here are pretty nicely summarised, I am just adding on the Python script used by me for manually cleaning only the artefacts on the latest version of GitLab linux installation (v16.10.3-ee).
I first retrieved the number of pages and projects I have in our GitLab environment, using the values "x-total-pages" and "x-total" of the command curl https://gitlab.company/api/v4/projects?private_token=<token> --head
. Then, I iterated through the GitLab projects in the paginated manner, and retrieved the project-IDs into a list. Lastly, I iterated through this list to perform the necessary artefact cleanup.
# This is a sample Python script referenced on the idea from https://mcmap.net/q/400016/-remove-artifacts-from-ci-manually
import json
import requests
def clean_gitlab_artefact():
base_url = "https://gitlab.company"
access_token = "access-token" # check with your GitLab project owner
print(f'GET /version')
x = (requests.get(f"{base_url}/api/v4/version", headers={"PRIVATE-TOKEN": access_token}))
print(x)
data = json.loads(x.text)
print(f'Using GitLab version {data["version"]}. Implemented on 16.10.3-ee!')
# # there were 173 projects at the time of running this script, which can be checked by exploring the
# # value "x-total" of the command `curl https://gitlab.company/api/v4/projects?private_token=<token> --head`
page = 1
total_project_ids = []
while page != 3:
print(f'GET /project-IDs')
projects = (requests.get(f"{base_url}/api/v4/projects?per_page=100&page={page}",
headers={"PRIVATE-TOKEN": access_token}))
page += 1
# print(projects)
data = json.loads(projects.text)
project_ids = [o["id"] for o in data]
total_project_ids += project_ids
print(total_project_ids)
for project_id in total_project_ids:
request_str = f'projects/{project_id}/artifacts'
url = f'{base_url}/api/v4/{request_str}'
print(f'DELETE /{request_str}')
x = (requests.delete(url, headers={"PRIVATE-TOKEN": access_token}))
print(x)
if __name__ == '__main__':
clean_gitlab_artefact()
And, please find below the output of the script which returns soon (with an accepted response 202 if the artefacts would be deleted asynchronously), as cleaning will happen in the background asynchronously, as also explained in other answers here.
copy([...$('a[title="Download artifacts"],a[download]').map((x, e) => /\/([0-9]+)\//.exec(e.href)[1])].join(' '))
. – Woothen