Implement interface to Jenkins
authorEd Bartosh <eduard.bartosh@intel.com>
Sun, 1 Feb 2015 10:01:55 +0000 (12:01 +0200)
committerEd Bartosh <eduard.bartosh@intel.com>
Tue, 3 Feb 2015 11:52:10 +0000 (13:52 +0200)
Implemented trigger_build function using 3rd party jenkinsapi. This
function will be used for rebuild, remove and lock/unlock functionality.

Change-Id: Idf55f4ed3c8dee51bdb51719fa338d68867b7b25
Signed-off-by: Ed Bartosh <eduard.bartosh@intel.com>
debian/control
packaging/repa.spec
repa.1
repa/jenkins.py [new file with mode: 0644]
repa/main.py

index 79738f9..1563322 100644 (file)
@@ -14,6 +14,7 @@ Depends: python (>=2.6),
          osc,
          gbs-api,
          python-setuptools,
+         python-jenkinsapi,
          ${misc:Depends},
          ${python:Depends}
 Description: tool to help release engineers to maintain code submissions
index 75d62a9..67fa065 100644 (file)
@@ -18,6 +18,7 @@ Requires:       gbs-api
 Requires:       osc
 Requires:       python >= 2.6
 Requires:       python-setuptools
+Requires:       python-jenkinsapi
 
 %description
 This tool is to assist release engineers to operate with submissions
diff --git a/repa.1 b/repa.1
index 8ae3320..099d2a0 100644 (file)
--- a/repa.1
+++ b/repa.1
@@ -382,6 +382,15 @@ apiuser = your_user_name
 apipasswd = your_password
 .RE
 .RS 2
+jenkins_url = https://build.tizen.org/robot
+.RE
+.RS 2
+jenkins_user = your_jenkins_user_name
+.RE
+.RS 2
+jenkins_passwd = your_jenkins_password
+.RE
+.RS 2
 processes = 20
 .RE
 .RS 2
@@ -405,7 +414,7 @@ noaggregate = mic-bootstrap-x86-arm.rpm|mic-bootstrap.rpm|mic-bootstrap-debugsou
 
 
 .RS 2
-Mandatory options: apiurl, apiuser, apipasswd and project
+Mandatory options: apiurl, apiuser, apipasswd, jenkins_url, jenkins_user, jenkins_passwd and project
 .RE
 
 .RS 2
diff --git a/repa/jenkins.py b/repa/jenkins.py
new file mode 100644 (file)
index 0000000..29759e8
--- /dev/null
@@ -0,0 +1,62 @@
+#!/usr/bin/env python
+#
+# This file is part of REPA: Release Engineering Process Assistant.
+#
+# Copyright (C) 2015 Intel Corporation
+#
+# REPA is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# version 2 as published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+# MA 02110-1301, USA.
+
+"""
+REPA: Release Engineering Process Assistant.
+
+Copyright (C) Intel Corporation 2015
+Licence: GPL version 2
+Author: Ed Bartosh <eduard.bartosh@intel.com>
+
+Jenkins module. Triggering Jenkins builds.
+"""
+
+from jenkinsapi.jenkins import Jenkins
+from requests import HTTPError, ConnectionError
+
+class JenkinsError(Exception):
+    """Local exception."""
+    pass
+
+def trigger_build(job, parameters, cred, block=True):
+    """
+    Trigger Jenkins build.
+
+    :param job: job name
+    :type job: string
+    :param parameters: job parameters
+    :type parameters: dictionary
+    :param cred: credentials
+    :type cred: named tuple cred.url, cred.username, cred.password
+    :param block: block the call until build is finished
+    :type block: bool
+    :returns: build number, build status, console output
+    """
+    try:
+        jenkins = Jenkins(cred.url, cred.username, cred.password)
+    except (HTTPError, ConnectionError) as error:
+        raise JenkinsError("Can't connect to jenkins: %s" % str(error))
+
+    if job not in jenkins:
+        raise JenkinsError("Job %s doesn't exist" % job)
+
+    qitem = jenkins[job].invoke(block=block, build_params=parameters)
+    build = qitem.get_build()
+    return build.get_number(), build.get_status(), build.get_console()
index 44680cc..39f42ec 100755 (executable)
@@ -83,7 +83,8 @@ def parse_args(argv):
 
 def read_config(paths=('/etc/repa.conf', expanduser('~/.repa.conf')),
                 section='general',
-                mandatory=('apiurl', 'apiuser', 'apipasswd', 'project')):
+                mandatory=('apiurl', 'apiuser', 'apipasswd', 'project',
+                           'jenkins_url', 'jenkins_user', 'jenkins_passwd')):
     """
     Read repa config.
     Configuration is read from the set of files provided.