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
=== modified file 'doc/index.rst'
--- doc/index.rst 2011-09-04 00:24:56 +0000
+++ doc/index.rst 2012-03-01 18:10:25 +0000
@@ -20,6 +20,8 @@
2020
21 # build a parameterized job21 # build a parameterized job
22 j.build_job('api-test', {'param1': 'test value 1', 'param2': 'test value 2'})22 j.build_job('api-test', {'param1': 'test value 1', 'param2': 'test value 2'})
23 build_info = j.get_build_info('build_name', next_build_number)
24 print(build_info)
2325
24Python Jenkins development is hosted on Launchpad: https://launchpad.net/python-jenkins26Python Jenkins development is hosted on Launchpad: https://launchpad.net/python-jenkins
2527
@@ -115,6 +117,14 @@
115117
116 :param name: Name of Jenkins job, ``str``118 :param name: Name of Jenkins job, ``str``
117119
120 .. method:: get_build_info(name, number)
121
122 Get build information dictionary.
123
124 :param name: Job name, ``str``
125 :param name: Build number, ``int``
126 :returns: dictionary of build information
127
118 .. method:: get_job_config(name) -> str128 .. method:: get_job_config(name) -> str
119129
120 Get configuration XML of existing Jenkins job. 130 Get configuration XML of existing Jenkins job.
121131
=== modified file 'jenkins/__init__.py'
--- jenkins/__init__.py 2011-09-04 00:24:56 +0000
+++ jenkins/__init__.py 2012-03-01 18:10:25 +0000
@@ -76,6 +76,7 @@
76COPY_JOB = 'createItem?name=%(to_name)s&mode=copy&from=%(from_name)s'76COPY_JOB = 'createItem?name=%(to_name)s&mode=copy&from=%(from_name)s'
77BUILD_JOB = 'job/%(name)s/build'77BUILD_JOB = 'job/%(name)s/build'
78BUILD_WITH_PARAMS_JOB = 'job/%(name)s/buildWithParameters'78BUILD_WITH_PARAMS_JOB = 'job/%(name)s/buildWithParameters'
79BUILD_INFO = 'job/%(name)s/%(number)d/api/json?depth=0'
7980
8081
81CREATE_NODE = 'computer/doCreateItem?%s'82CREATE_NODE = 'computer/doCreateItem?%s'
@@ -188,6 +189,33 @@
188 if e.code in [401, 403, 500]:189 if e.code in [401, 403, 500]:
189 raise JenkinsException('Error in request. Possibly authentication failed [%s]'%(e.code))190 raise JenkinsException('Error in request. Possibly authentication failed [%s]'%(e.code))
190 # right now I'm getting 302 infinites on a successful delete191 # right now I'm getting 302 infinites on a successful delete
192
193 def get_build_info(self, name, number):
194 '''
195 Get information on this Master. This information
196 includes status of build.
197
198 :returns: dictionary of information about build, ``dict``
199
200 Example::
201
202 >>> next_build_number = j.get_job_info('build_name')['next_build_number']
203 >>> output = j.build_job('build_'+kwargs['vcs_server_type'], params)
204 >>> sleep(10)
205 >>> build_info = j.get_build_info('build_name', next_build_number)
206 >>> print(build_info)
207 {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'}
208 '''
209 try:
210 response = self.jenkins_open(urllib2.Request(self.server + BUILD_INFO%locals()))
211 if response:
212 return json.loads(response)
213 else:
214 raise JenkinsException('job[%s] number[%d] does not exist'%(name, number))
215 except urllib2.HTTPError:
216 raise JenkinsException('job[%s] number[%d] does not exist'%(name, number))
217 except ValueError:
218 raise JenkinsException('Could not parse JSON info for job[%s] number[%d]'%(name, number))
191 219
192 def get_queue_info(self):220 def get_queue_info(self):
193 '''221 '''

Subscribers

People subscribed via source and target branches