How to get the last build date/time via groovy script

4,190 views
Skip to first unread message

grayaii

unread,
May 2, 2011, 5:05:35 PM5/2/11
to jenkins...@googlegroups.com
Noobie Quesiton: How do I get the last build date/time of a job?
I can get all sorts of information, but i can't figure out how to get when
the last (either successful or failure) build time was.

For instance:
j = hudson.model.Hudson.instance.getJob("myjob")
prinln j.getName()
println j.isBuilding()
println j.isInQueue()

How do i get the date of the last build?
I assume i have to this, but then what?:
runt = j.getLastBuild()
runt.????? -> (I can't figure out which function to call)

Thanks

--
View this message in context: http://jenkins.361315.n4.nabble.com/How-to-get-the-last-build-date-time-via-groovy-script-tp3490988p3490988.html
Sent from the Jenkins users mailing list archive at Nabble.com.

Ian C. Roberts

unread,
May 3, 2011, 6:17:52 AM5/3/11
to jenkins...@googlegroups.com
This should work

item = hudson.model.Hudson.instance.getItem("job_name")
build = item.getLastBuild()

println build.getTime()

(you can use getLastStableBuild, or getLastFailedBuild() or any of the others depending on what you want)

Ian

grayaii

unread,
May 3, 2011, 11:41:12 AM5/3/11
to jenkins...@googlegroups.com
Thanks! That was exactly what I was looking for... and of course if I looked
harder in the API spec I would have found it (20/20 hindsight), but you
saved me a lot of time.

--
View this message in context: http://jenkins.361315.n4.nabble.com/How-to-get-the-last-build-date-time-via-groovy-script-tp3490988p3492811.html

Reply all
Reply to author
Forward
0 new messages