Remove all artifacts in project
The snippet can be accessed without any authentication.
Authored by
Dmytro Bogatov
rm-artifacts.py 1.17 KiB
#!/usr/bin/env python3
import time
import requests
project_id = '146'
token = '...'
server = 'git.dbogatov.org'
print("Creating list of all jobs that currently have artifacts...")
# We skip the first page.
url = f"https://{server}/api/v4/projects/{project_id}/jobs?per_page=100&page=2"
while url:
print(f"Processing page: {url}")
response = requests.get(
url,
headers={
'private-token': token,
},
)
if response.status_code in [500, 429]:
print(f"Status {response.status_code}, retrying.")
time.sleep(10)
continue
response.raise_for_status()
response_json = response.json()
# print(response_json)
# exit()
for job in response_json:
if job.get('artifacts_expire_at', None):
job_id = job['id']
delete_response = requests.delete(
f"https://{server}/api/v4/projects/{project_id}/jobs/{job_id}/artifacts",
headers={
'private-token': token,
},
)
print(f"Processing job ID: {job_id} - status: {delete_response.status_code}")
url = response.links.get('next', {}).get('url', None)
Please register or sign in to comment