Reputation: 41
I would like to obtain the date of builds from Jenkins to be inserted into a dashboard for documentation purpose. Is there any function to get the date? Thanks.
Used server.get_build_info()
but failed to obtain the date
Upvotes: 0
Views: 1334
Reputation: 4203
Since you are using Python Jenkins, you can get the timestamp of the build and convert to date format as follows:
import jenkins
from datetime import datetime
server = jenkins.Jenkins('<jenkins_url>', username="<your_username>", password="<password/API token>")
time_stamp = server.get_build_info('<your_job_name>', number, depth=0)['timestamp']/1000
date_time = datetime.fromtimestamp(time_stamp)
Output:
>>> print(time_stamp)
1565012814
>>> print(date_time)
2019-08-05 19:16:54
Upvotes: 3