osmith has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-ci/+/42635?usp=email )
Change subject: jenkins-gerrit/artifacts_download: new script ......................................................................
jenkins-gerrit/artifacts_download: new script
Add a script for downloading artifacts from the build job in a gerrit pipeline, so it can be used in the hwtest job job.
pipeline: <--- URL to the pipeline is passed to all jobs parallel: sequential: build <--- artifacts are here hwtest <--- will call the new script with the pipeline URL lint binpkgs ...
Related: SYS#7963 Change-Id: Ia96951d62b464b2e0b80f8e555cb77e5b9e52f78 --- A scripts/jenkins-gerrit/artifacts_download.py 1 file changed, 68 insertions(+), 0 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-ci refs/changes/35/42635/1
diff --git a/scripts/jenkins-gerrit/artifacts_download.py b/scripts/jenkins-gerrit/artifacts_download.py new file mode 100755 index 0000000..d576e06 --- /dev/null +++ b/scripts/jenkins-gerrit/artifacts_download.py @@ -0,0 +1,68 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright 2026 sysmocom - s.f.m.c. GmbH info@sysmocom.de +import argparse +import io +import re +import shutil +import sys +import urllib.request +import zipfile +import os + +jenkins_url = "https://jenkins.osmocom.org" +re_start_build = re.compile("Starting building: gerrit-[a-zA-Z-_0-9]* #[0-9]*") +matrix = "a1=default,a2=default,a3=default,a4=default,label=osmocom-gerrit" + + +def parse_args(): + parser = argparse.ArgumentParser(description="Download artifacts from the gerrit pipeline.") + parser.add_argument( + "pipeline_url", + help="$BUILD_URL of the pipeline job, e.g." + " https://jenkins.osmocom.org/jenkins/job/gerrit-osmo-ccid-firmware/177/", + ) + return parser.parse_args() + + +def get_job_url(pipeline_url): + url = f"{pipeline_url}/consoleText" + print(f"GET {url}") + with urllib.request.urlopen(url) as response: + for line in io.TextIOWrapper(response, encoding="utf-8"): + for match in re_start_build.findall(line): + job_name = match.split(" ")[2] + if not job_name.endswith("-build"): + continue + job_id = int(match.split(" ")[3].replace("#", "")) + job_url = f"{jenkins_url}/jenkins/job/{job_name}/{matrix}/{job_id}" + return job_url + + print("ERROR: failed to find job URL!") + sys.exit(1) + + +def download_archive_zip(job_url): + url = f"{job_url}/artifact/*zip*/archive.zip" + print(f"GET {url}") + with urllib.request.urlopen(url) as response, open("archive.zip", "wb") as handle: + shutil.copyfileobj(response, handle) + + +def extract_archive_zip(): + path = os.path.join(os.getcwd(), "gerrit-artifacts") + os.makedirs(path) + print(f"UNZIP archive.zip to {path}") + with zipfile.ZipFile("archive.zip") as z: + z.extractall(path) + + +def main(): + args = parse_args() + job_url = get_job_url(args.pipeline_url) + download_archive_zip(job_url) + extract_archive_zip() + + +if __name__ == "__main__": + main()