Reputation: 1338
I am trying to use python's jenkinsapi
to automate some builds. It looks like everything works fine, and the build is successful. However, when I check the status through my script to ensure the success of the build, I get a None
value rather than the expected 'SUCCESS'. If I open a new python shell and query the same build for its status, I do get the 'SUCCESS' value.
My code is:
from jenkinsapi.jenkins import Jenkins
from time import sleep
jk = Jenkins(jenkins_url,user,password)
my_job = jk['my_job']
params = {'param_1': 'value_1', 'param_2': 'value_2',...}
build_num = my_job.get_next_build_number()
print(build_num) # will print the right number, for example 174
my_job.invoke(build_params=params)
sleep(10)
build = my_job.get_build(build_num)
while build.is_running():
sleep(3)
sleep(10)
print(build.get_status()) # will print 'None'
if build.get_status() != 'SUCCESS':
sys.exit('Jenkins build failed')
As you see, I have added some 'sleeps' to make sure this is not a latency issue (tried longer periods too). I have also tried using the build.block_until_complete()
method, but it doesn't seem to do anything.
Any ideas why I am receiving this status, despite the success of the build?
Thanks!
Upvotes: 2
Views: 1097
Reputation: 3356
Looks like build.py:get_status() is a getter for an offline object and does not automatically keep the build-object in sync with the server and calling is_running()
only syncs a subset of the jobs attributes. Therefore you'll either have to refresh/get a new build-object with build = my_job.get_build(build_num)
or force poll the existing build-object build.poll()
and then verify the status with build.get_status() == jenkinsapi.constants.STATUS_SUCCESS
.
Upvotes: 3