← Back to team overview

sts-sponsors team mailing list archive

[Merge] ~alexsander-souza/maas/+git/maas-release-tools:nice_jenkins_errors into ~maas-committers/maas/+git/maas-release-tools:main

 

Alexsander de Souza has proposed merging ~alexsander-souza/maas/+git/maas-release-tools:nice_jenkins_errors into ~maas-committers/maas/+git/maas-release-tools:main.

Commit message:
Better Jenkins error handling

Requested reviews:
  MAAS Committers (maas-committers)

For more details, see:
https://code.launchpad.net/~alexsander-souza/maas/+git/maas-release-tools/+merge/442130
-- 
Your team MAAS Committers is requested to review the proposed merge of ~alexsander-souza/maas/+git/maas-release-tools:nice_jenkins_errors into ~maas-committers/maas/+git/maas-release-tools:main.
diff --git a/maas_release_tools/maasci.py b/maas_release_tools/maasci.py
index 4c96ce4..2a6956a 100644
--- a/maas_release_tools/maasci.py
+++ b/maas_release_tools/maasci.py
@@ -19,6 +19,10 @@ class JenkinsConnectionFailed(Exception):
     pass
 
 
+class JenkinsConfigMissing(Exception):
+    pass
+
+
 class JenkinsActions:
     def __init__(
         self,
@@ -42,6 +46,10 @@ class JenkinsActions:
         server_section = server_section or JJB_SECTION
         config = configparser.ConfigParser()
         config.read(jenkins_config)
+        if not config.has_section(server_section):
+            raise JenkinsConfigMissing(
+                f"file {jenkins_config} has no '{server_section}' section"
+            )
         url = config[server_section]["url"]
         kwargs = {
             "username": config[server_section]["user"],
diff --git a/maas_release_tools/scripts/release_status.py b/maas_release_tools/scripts/release_status.py
index 67ecb57..7beeac4 100644
--- a/maas_release_tools/scripts/release_status.py
+++ b/maas_release_tools/scripts/release_status.py
@@ -38,6 +38,7 @@ from ..launchpad import (
 )
 from ..maasci import (
     JenkinsActions,
+    JenkinsConfigMissing,
     JenkinsConnectionFailed,
     JJB_CONFIG,
     JJB_FAILURE,
@@ -1396,11 +1397,16 @@ def main():
         credentials_file=args.launchpad_credentials,
         dry_run=args.dry_run,
     )
-    jenkins = JenkinsActions(
-        dry_run=args.jenkins_skip,
-        jenkins_config=args.jenkins_config,
-        server_section=args.jenkins_section,
-    )
+    try:
+        jenkins = JenkinsActions(
+            dry_run=args.jenkins_skip,
+            jenkins_config=args.jenkins_config,
+            server_section=args.jenkins_section,
+        )
+    except JenkinsConfigMissing as e:
+        print("Jenkins API not configured:")
+        print(e, file=sys.stderr)
+        return 1
     release_version = ReleaseVersion(args.version)
     preparer = ReleasePreparer(
         release_version,

Follow ups