sts-sponsors team mailing list archive
-
sts-sponsors team
-
Mailing list archive
-
Message #03574
Re: [Merge] ~alexsander-souza/maas/+git/maas-release-tools:add_jenkins into ~maas-committers/maas/+git/maas-release-tools:main
Review: Needs Information
Currently this looks at the last build, but that might not be related to the repo/branch we're looking for.
Is there a way to filter jobs by parameters so that we can look at the right branch?
Diff comments:
> diff --git a/maas_release_tools/maasci.py b/maas_release_tools/maasci.py
> new file mode 100644
> index 0000000..099df77
> --- /dev/null
> +++ b/maas_release_tools/maasci.py
> @@ -0,0 +1,53 @@
> +"""Interact with Jenkins API"""
> +import configparser
> +from functools import cached_property
> +import logging
> +from os.path import expanduser
> +from pathlib import Path
> +from typing import Optional, Tuple
> +
> +from jenkins import Jenkins
> +
> +JJB_CONFIG = Path("~/.config/jenkins_jobs/jenkins_jobs.ini")
you can use Path(...).expanduser() here, and drop the os.path one later
> +JJB_SECTION = "maas-integration-ci"
> +
> +
> +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 Path(expanduser(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]:
> + 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"])
--
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.
Follow ups
References