Skip to content
Snippets Groups Projects
Commit 8bcaa426 authored by Jonas Höppner's avatar Jonas Höppner
Browse files

scripts: Add delete_job_artifacts script to delete all artifacts from untagged jobs

For a given project all artifacts may be deleted. This was needed due to
space limitations on the gitlab server.
parent 28906544
No related branches found
No related tags found
1 merge request!234scripts: Add delete_job_artifacts script to delete all artifacts from untagged jobs
Pipeline #47964 skipped with stage
#!/usr/bin/env python3
"""
Query job by project and tag.
Delete job artifacts if it is not a git tag (release)
"""
import argparse
import logging
import sys
import gitlab as gl
__author__ = "Jonas Höppner"
__email__ = "jonas.hoeppner@garz-fricke.com"
GITLAB_SERVER = "https://git.seco.com"
# ID of the guf_yocto group
GITLAB_GROUP_ID = "556"
DISTRO_PROJECT_ID = "1748"
MACHINE_PROJECT_ID = "2074"
MANIFEST_PROJECT_ID = "1725"
DEFAULTBRANCH = "dunfell"
GITLAB_TIMEFORMAT = "%Y-%m-%dT%H:%M:%S.%f%z"
TIMEFORMAT = "%Y-%m-%d %H:%M"
verbose = 0
def main(args):
parser = argparse.ArgumentParser(description=__doc__, usage="%(prog)s [OPTIONS]")
parser.add_argument(
"--gitlab-url",
help="""URL to the GitLab instance""",
dest="gitlab_url",
action="store",
default=GITLAB_SERVER,
)
parser.add_argument(
"--token",
help="""GitLab REST API private access token""",
dest="token",
required=True,
)
parser.add_argument(
"--project",
help="""GitLab project where the jobs are queried from""",
dest="project",
default="seco-ne/yocto/manifest",
)
parser.add_argument(
"--filter-tag", help="""Only jobs with this gitlab job tag set""", default=None
)
parser.add_argument(
"--filter-status", help="""Only jobs with this this status""", default=None
)
parser.add_argument(
"-v",
"--verbose",
action="count",
dest="verbose",
default=0,
help=("Increase verbosity."),
)
options = parser.parse_args(args)
if options.verbose:
logging.basicConfig(level=logging.DEBUG)
logging.debug(options)
gitlab = gl.Gitlab(options.gitlab_url, private_token=options.token)
project = gitlab.projects.get(options.project)
job_it = project.jobs.list(iterator=True)
for job in job_it:
# Skip release tags
if job.tag:
continue
if options.filter_status is not None and job.status != options.filter_status:
continue
if options.filter_tag is not None:
if not options.filter_tag in job.tag_list:
continue
job.delete_artifacts()
logging.debug(
"Deleted artifacts for %s: %s %s.",
job.name,
job.status,
str(job.tag_list),
)
if __name__ == "__main__":
main(sys.argv[1:])
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment