Merged branch to add get_build_info method

This commit is contained in:
James Page 2012-03-02 16:31:05 +00:00
commit a64d11bd47
2 changed files with 56 additions and 17 deletions

View File

@ -20,6 +20,8 @@ Example usage::
# build a parameterized job
j.build_job('api-test', {'param1': 'test value 1', 'param2': 'test value 2'})
build_info = j.get_build_info('build_name', next_build_number)
print(build_info)
Python Jenkins development is hosted on Launchpad: https://launchpad.net/python-jenkins
@ -115,6 +117,14 @@ API documentation
:param name: Name of Jenkins job, ``str``
.. method:: get_build_info(name, number)
Get build information dictionary.
:param name: Job name, ``str``
:param name: Build number, ``int``
:returns: dictionary of build information
.. method:: get_job_config(name) -> str
Get configuration XML of existing Jenkins job.

View File

@ -76,6 +76,7 @@ DISABLE_JOB = 'job/%(name)s/disable'
COPY_JOB = 'createItem?name=%(to_name)s&mode=copy&from=%(from_name)s'
BUILD_JOB = 'job/%(name)s/build'
BUILD_WITH_PARAMS_JOB = 'job/%(name)s/buildWithParameters'
BUILD_INFO = 'job/%(name)s/%(number)d/api/json?depth=0'
CREATE_NODE = 'computer/doCreateItem?%s'
@ -189,6 +190,34 @@ class Jenkins(object):
raise JenkinsException('Error in request. Possibly authentication failed [%s]'%(e.code))
# right now I'm getting 302 infinites on a successful delete
def get_build_info(self, name, number):
'''
Get build information dictionary.
:param name: Job name, ``str``
:param name: Build number, ``int``
:returns: dictionary of build information, ``dict``
Example::
>>> next_build_number = j.get_job_info('build_name')['next_build_number']
>>> output = j.build_job('build_'+kwargs['vcs_server_type'], params)
>>> sleep(10)
>>> build_info = j.get_build_info('build_name', next_build_number)
>>> print(build_info)
{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'}
'''
try:
response = self.jenkins_open(urllib2.Request(self.server + BUILD_INFO%locals()))
if response:
return json.loads(response)
else:
raise JenkinsException('job[%s] number[%d] does not exist'%(name, number))
except urllib2.HTTPError:
raise JenkinsException('job[%s] number[%d] does not exist'%(name, number))
except ValueError:
raise JenkinsException('Could not parse JSON info for job[%s] number[%d]'%(name, number))
def get_queue_info(self):
'''
:returns: list of job dictionaries, ``[dict]``