'Get Last Failure and Last Success time jenkinsAPI
I want to get these marked time of last success and last failure (present in image) using python code by jenkinsAPI
HERE IS THE CODE
from jenkinsapi.jenkins import Jenkins
from datetime import datetime
def get_server_instance():
jenkins_url = 'http://localhost:8080'
server = Jenkins(jenkins_url, username='vidit', password='******')
return server
def get_job_details():
server = get_server_instance()
for j in server.get_jobs():
#print(j)
job_instance = server.get_job(j[0])
print('Job Name:%s' %(j[1].name))
print('Job Description:%s' %(job_instance.get_description()))
print('Is Job running:%s' %(job_instance.is_running()))
print('Is Job enabled:%s' %(job_instance.is_enabled()))
try:
S1=job_instance.get_build(job_instance.get_last_good_buildnumber())
print(S1.get_timestamp())
except:
print("NA")
try:
F1=j[1].get_build(j[1].get_last_failed_buildnumber())
print(F1.get_timestamp())
except:
print("NA")
if __name__ == '__main__':
print(get_server_instance().version)
#print(get_server_instance())
get_job_details()
HERE IS THE OUTPUT:
2.319.3
Job Name:sample2
Job Description:
Is Job running:False
Is Job enabled:True
2022-04-28 09:27:57+00:00 # Here i need same time like "1day3hrs" marked in image
2022-04-28 09:37:56+00:00 #
Job Name:simple1
Job Description:
Is Job running:False
Is Job enabled:True
2022-04-28 09:16:48+00:00 # Here i need same time like "1day3hrs" marked in image
NA #
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
