sts-sponsors team mailing list archive
-
sts-sponsors team
-
Mailing list archive
-
Message #03755
Re: [Merge] ~alexsander-souza/maas/+git/maas-release-tools:add_jenkins into ~maas-committers/maas/+git/maas-release-tools:main
nice, +1
one comment inline
Diff comments:
> diff --git a/maas_release_tools/maasci.py b/maas_release_tools/maasci.py
> new file mode 100644
> index 0000000..faa8df9
> --- /dev/null
> +++ b/maas_release_tools/maasci.py
> @@ -0,0 +1,70 @@
> +"""Interact with Jenkins API"""
> +import configparser
> +from functools import cached_property
> +import logging
> +from pathlib import Path
> +import re
> +from typing import Optional, Tuple
> +
> +from jenkins import Jenkins
> +
> +JJB_CONFIG = Path("~/.config/jenkins_jobs/jenkins_jobs.ini").expanduser()
> +JJB_SECTION = "maas-integration-ci"
> +
> +JJB_REV_RE = re.compile(r"^.+-g\.(?P<gitrev>[0-9a-z]{9})(-.*)?$")
> +JJB_FAILURE = "FAILURE"
> +
> +
> +class JenkinsActions:
> + def __init__(
> + self,
> + server_section: Optional[str] = None,
> + jenkins_config: Optional[Path] = None,
> + dry_run: bool = False,
> + ):
> + self._jenkins = self._get_client(
> + server_section=server_section, jenkins_config=jenkins_config
> + )
> + self.logger = logging.getLogger("jenkins")
> + self.dry_run = dry_run
> +
> + def _get_client(
> + self,
> + server_section: Optional[str] = None,
> + jenkins_config: Optional[Path] = None,
> + ) -> Jenkins:
> + """Return a Jenkins API client."""
> + jenkins_config = jenkins_config or JJB_CONFIG
> + server_section = server_section or JJB_SECTION
> + config = configparser.ConfigParser()
> + config.read(jenkins_config)
> + url = config[server_section]["url"]
> + kwargs = {
> + "username": config[server_section]["user"],
> + "password": config[server_section]["password"],
> + }
> + return Jenkins(url, **kwargs)
> +
> + @cached_property
> + def me(self) -> str:
> + return self._jenkins.get_whoami()["id"]
> +
> + def get_last_build_result(self, job_name: str) -> Tuple[str, str]:
this seems unused, can it be dropped?
> + job = self._jenkins.get_job_info(job_name)
> + last_build = job["lastCompletedBuild"]["number"]
> + build_info = self._jenkins.get_build_info(job_name, last_build)
> + return str(build_info["result"]), str(build_info["url"])
> +
> + def get_last_build_result_for_rev(
> + self, job_name: str, rev: str
> + ) -> Tuple[str, str]:
> + job = self._jenkins.get_job_info(job_name)
> + for build in job["builds"]:
> + build_info = self._jenkins.get_build_info(
> + job_name, build["number"]
> + )
> + if build_info["description"] is not None:
> + match = JJB_REV_RE.match(build_info["description"])
> + if match and match.group("gitrev") == rev:
> + return str(build_info["result"]), str(build_info["url"])
> + return JJB_FAILURE, str(job["url"])
--
https://code.launchpad.net/~alexsander-souza/maas/+git/maas-release-tools/+merge/433614
Your team MAAS Committers is subscribed to branch ~maas-committers/maas/+git/maas-release-tools:main.
References