Question

Here is what I am doing using the JenkinsAPI for Python

# Python scipt to get build information

# Import jenkins API and check Jenkins Version

import jenkinsapi
from jenkinsapi.jenkins import Jenkins
from jenkinsapi.build import Build

J = Jenkins('http://test.com')
job = J['MY_JOB_NAME']

print "Jenkins version:", J.version, "\n"

print jenkinsapi.api.get_latest_test_results('http://test.com','MY_JOB_NAME'), "\n"


B= Build('http://test.com',22,job)
print B.get_resultset()

I keep getting this error which I am unable to understand:

Traceback (most recent call last):
  File "myscript.py", line 19, in <module>
    print B
  File "/usr/local/lib/python2.7/dist-packages/jenkinsapi-0.2.18-py2.7.egg/jenkinsapi/build.py", line 49, in __str__
    return self._data['fullDisplayName']
KeyError: 'fullDisplayName'
svikani@myunix:~$ python myscript.py
Traceback (most recent call last):
  File "myscript.py", line 19, in <module>
    print B.get_resultset()
  File "/usr/local/lib/python2.7/dist-packages/jenkinsapi-0.2.18-py2.7.egg/jenkinsapi/build.py", line 331, in get_resultset
    result_url = self.get_result_url()
  File "/usr/local/lib/python2.7/dist-packages/jenkinsapi-0.2.18-py2.7.egg/jenkinsapi/build.py", line 325, in get_result_url
    return url_tpl % (self._data["url"], config.JENKINS_API)
KeyError: 'url'
Was it helpful?

Solution

It looks like there are uninitialized variables in the Build instance.

You're constructing a Build instance yourself, but you should probably go through the API of the Jenkins instance to get the job and the build you're interested in.

import jenkinsapi
j = jenkinsapi.jenkins.Jenkins('http://jenkins:8080/')
job = j.get_job(JOB_NAME)  # or j[JOB_NAME]
build = job.get_build(BUILD_ID)
print build.get_resultset()
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top