Merge lp:~kenrumer/python-jenkins/build_info into lp:~python-jenkins-developers/python-jenkins/trunk

Proposed by Ken Rumer
Status: Merged
Merged at revision: 13
Proposed branch: lp:~kenrumer/python-jenkins/build_info
Merge into: lp:~python-jenkins-developers/python-jenkins/trunk
Diff against target: 73 lines (+38/-0)
2 files modified
doc/index.rst (+10/-0)
jenkins/__init__.py (+28/-0)
To merge this branch: bzr merge lp:~kenrumer/python-jenkins/build_info
Reviewer Review Type Date Requested Status
James Page Approve
Review via email: mp+95243@code.launchpad.net

Commit message

Added build info method

Description of the change

Try this again.

Gets build information from Jenkins. Can use to get the status of a build. Loop until the build is complete, return the artifact URL(s).

Example usage:
     import jenkins
     import time
     j = jenkins.Jenkins('http://'+kwargs['ci_host']+':'+kwargs['ci_port'], kwargs['ci_username'], kwargs['ci_password'])

    next_build_number = j.get_job_info('build_'+kwargs['vcs_server_type'])['nextBuildNumber']

To post a comment you must log in.
Revision history for this message
James Page (james-page) wrote :

Thanks for re-doing this merge proposal Ken.

A few comments:

1) Please could you add documentation to the method in the python code as well as index.rst - helps folk who 'pydoc jenkins'.

2) The string handling for errors is inconsistent with the rest of the package:

Please use:

  raise JenkinsException('job[%s] number[%d] does not exist'%(name, number))

instead of:

  raise JenkinsException('job[!s] number[!d] does not exist'.format(name, number))

I appreciate that both produce the same result but I would like to keep the package consistent.

Other than that looks good - I'll merge once you have made the above amendments.

Cheers

James

review: Needs Fixing
Revision history for this message
Ken Rumer (kenrumer) wrote :

Cool, thanks for the info
On Mar 1, 2012 2:05 AM, "James Page" <email address hidden> wrote:

> Review: Needs Fixing
>
> Thanks for re-doing this merge proposal Ken.
>
> A few comments:
>
> 1) Please could you add documentation to the method in the python code as
> well as index.rst - helps folk who 'pydoc jenkins'.
>
> 2) The string handling for errors is inconsistent with the rest of the
> package:
>
> Please use:
>
> raise JenkinsException('job[%s] number[%d] does not exist'%(name, number))
>
> instead of:
>
> raise JenkinsException('job[!s] number[!d] does not exist'.format(name,
> number))
>
> I appreciate that both produce the same result but I would like to keep
> the package consistent.
>
> Other than that looks good - I'll merge once you have made the above
> amendments.
>
> Cheers
>
> James
>
> --
> https://code.launchpad.net/~kenrumer/python-jenkins/build_info/+merge/95243
> You are the owner of lp:~kenrumer/python-jenkins/build_info.
>

14. By Ken Rumer

Updated documentation, updated error handler for consistency

Revision history for this message
James Page (james-page) wrote :

+1 LGTM

review: Approve
Revision history for this message
Ken Rumer (kenrumer) wrote :

LinkedIn
------------

I'd like to add you to my professional network on LinkedIn.

- Ken

Ken Rumer
Senior Infrastructure Architect at Level 3 Communications
Greater Denver Area

Confirm that you know Ken Rumer:
https://www.linkedin.com/e/ndq7z5-h3w07ta4-4p/isd/7630157916/Wp-_FT85/?hs=false&tok=1ZVl6N6uxhYBg1

--
You are receiving Invitation to Connect emails. Click to unsubscribe:
http://www.linkedin.com/e/ndq7z5-h3w07ta4-4p/XtL1dnmsjKkORxJNXvUC0wrvDLrNPW1l9IVJGpYK8D/goo/mp%2B95243%40code%2Elaunchpad%2Enet/20061/I2583562695_1/?hs=false&tok=1qAnWDFTdhYBg1

(c) 2012 LinkedIn Corporation. 2029 Stierlin Ct, Mountain View, CA 94043, USA.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'doc/index.rst'
2--- doc/index.rst 2011-09-04 00:24:56 +0000
3+++ doc/index.rst 2012-03-01 18:10:25 +0000
4@@ -20,6 +20,8 @@
5
6 # build a parameterized job
7 j.build_job('api-test', {'param1': 'test value 1', 'param2': 'test value 2'})
8+ build_info = j.get_build_info('build_name', next_build_number)
9+ print(build_info)
10
11 Python Jenkins development is hosted on Launchpad: https://launchpad.net/python-jenkins
12
13@@ -115,6 +117,14 @@
14
15 :param name: Name of Jenkins job, ``str``
16
17+ .. method:: get_build_info(name, number)
18+
19+ Get build information dictionary.
20+
21+ :param name: Job name, ``str``
22+ :param name: Build number, ``int``
23+ :returns: dictionary of build information
24+
25 .. method:: get_job_config(name) -> str
26
27 Get configuration XML of existing Jenkins job.
28
29=== modified file 'jenkins/__init__.py'
30--- jenkins/__init__.py 2011-09-04 00:24:56 +0000
31+++ jenkins/__init__.py 2012-03-01 18:10:25 +0000
32@@ -76,6 +76,7 @@
33 COPY_JOB = 'createItem?name=%(to_name)s&mode=copy&from=%(from_name)s'
34 BUILD_JOB = 'job/%(name)s/build'
35 BUILD_WITH_PARAMS_JOB = 'job/%(name)s/buildWithParameters'
36+BUILD_INFO = 'job/%(name)s/%(number)d/api/json?depth=0'
37
38
39 CREATE_NODE = 'computer/doCreateItem?%s'
40@@ -188,6 +189,33 @@
41 if e.code in [401, 403, 500]:
42 raise JenkinsException('Error in request. Possibly authentication failed [%s]'%(e.code))
43 # right now I'm getting 302 infinites on a successful delete
44+
45+ def get_build_info(self, name, number):
46+ '''
47+ Get information on this Master. This information
48+ includes status of build.
49+
50+ :returns: dictionary of information about build, ``dict``
51+
52+ Example::
53+
54+ >>> next_build_number = j.get_job_info('build_name')['next_build_number']
55+ >>> output = j.build_job('build_'+kwargs['vcs_server_type'], params)
56+ >>> sleep(10)
57+ >>> build_info = j.get_build_info('build_name', next_build_number)
58+ >>> print(build_info)
59+ {u'building': False, u'changeSet': {u'items': [{u'date': u'2011-12-19T18:01:52.540557Z', u'msg': u'test', u'revision': 66, u'user': u'unknown', u'paths': [{u'editType': u'edit', u'file': u'/branches/demo/index.html'}]}], u'kind': u'svn', u'revisions': [{u'module': u'http://eaas-svn01.i3.level3.com/eaas', u'revision': 66}]}, u'builtOn': u'', u'description': None, u'artifacts': [{u'relativePath': u'dist/eaas-87-2011-12-19_18-01-57.war', u'displayPath': u'eaas-87-2011-12-19_18-01-57.war', u'fileName': u'eaas-87-2011-12-19_18-01-57.war'}, {u'relativePath': u'dist/eaas-87-2011-12-19_18-01-57.war.zip', u'displayPath': u'eaas-87-2011-12-19_18-01-57.war.zip', u'fileName': u'eaas-87-2011-12-19_18-01-57.war.zip'}], u'timestamp': 1324317717000, u'number': 87, u'actions': [{u'parameters': [{u'name': u'SERVICE_NAME', u'value': u'eaas'}, {u'name': u'PROJECT_NAME', u'value': u'demo'}]}, {u'causes': [{u'userName': u'anonymous', u'shortDescription': u'Started by user anonymous'}]}, {}, {}, {}], u'id': u'2011-12-19_18-01-57', u'keepLog': False, u'url': u'http://eaas-jenkins01.i3.level3.com:9080/job/build_war/87/', u'culprits': [{u'absoluteUrl': u'http://eaas-jenkins01.i3.level3.com:9080/user/unknown', u'fullName': u'unknown'}], u'result': u'SUCCESS', u'duration': 8826, u'fullDisplayName': u'build_war #87'}
60+ '''
61+ try:
62+ response = self.jenkins_open(urllib2.Request(self.server + BUILD_INFO%locals()))
63+ if response:
64+ return json.loads(response)
65+ else:
66+ raise JenkinsException('job[%s] number[%d] does not exist'%(name, number))
67+ except urllib2.HTTPError:
68+ raise JenkinsException('job[%s] number[%d] does not exist'%(name, number))
69+ except ValueError:
70+ raise JenkinsException('Could not parse JSON info for job[%s] number[%d]'%(name, number))
71
72 def get_queue_info(self):
73 '''

Subscribers

People subscribed via source and target branches