I have a script in python, that trigger-start few jenkins (import jenkins) jobs and then wait for their results. Works very good, but once a week in random day and time it fails with jenkins in fault(per logs and time, it looks like LDAP cause, authentication issue). Jenkins's LDAP is hosted, so I cannot do about it anything, as also in my own session via Firefox I have to reconnect. This problem happens mainly during check of jenkins job status, whereas the triggered job can run even for 8 hours. I tried adding try-catch and in catch recreate the session, but the exception happens more up in script's try-catch, so script stops and return failure.
Is there a way to tell python to jenkins to retry jenkins connection it if fails? I have seen the "timeout=" but that is for delay.
Part of code, which fails in line "build_info = jenkinsinstance" and script get exception and stopped
jenkinsinstance = jenkins.Jenkins('https://url:8080', username=user, password=pass)
...
<while cycle with sleep contains cycle for started jobs>
try:
build_info = jenkinsinstance.get_build_info(job["job_name"], job["build_ID"])
if build_info.get("result") is None:
print("{job_name} is in progress".format(job_name=job["job_name"]))
else:
print("{job_name} has finished".format(job_name=job["job_name"]))
job["build_status"] = build_info.get("result")
except (NameError, TypeError) as ReturnError:
print("{job_name} unknown status")
Added try-catch to catch and do a workaround, but still the script ends. I suppose the jenkins module cannot re-cover and re-try, if there is any connection issue.