Install the EnvInject plugin 
(https://wiki.jenkins-ci.org/display/JENKINS/EnvInject+Plugin).

In your job, make your first step get the current time in the format you prefer 
and write that out to a file called times.properties.  Here is how in Linux:

touch times.properties # create the file
TIME=date +%s # seconds since epoch
echo START_TIME = ${TIME} >> times.properties

After you finish the main job, have your next step write another timestamp to 
times.properties

TIME=date +%s # seconds since epoch
echo END_TIME = ${TIME} >> times.properties

Then create an "Inject environment variables" step (which requires the plugin) 
and load them from times.properties.

Finally, open up another shell step and you will have START_TIME and END_TIME 
as environment variables.  Do the math, et voila!

--Rob

-----Original Message-----
From: [email protected] 
[mailto:[email protected]] On Behalf Of heinst
Sent: Wednesday, July 02, 2014 12:55 PM
To: [email protected]
Subject: Get build duration using post-build Groovy script

I have a post build script and am trying to get the build duration. I am trying 
to get it like so:

def build = manager.build
build.duration.toString()

but that just yields 0. Is there a way I can get the build duration using a 
post build groovy script?



--
View this message in context: 
http://jenkins-ci.361315.n4.nabble.com/Get-build-duration-using-post-build-Groovy-script-tp4709134.html
Sent from the Jenkins users mailing list archive at Nabble.com.

--
You received this message because you are subscribed to the Google Groups 
"Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.


 Click 
https://www.mailcontrol.com/sr/AeynyPUxbszGX2PQPOmvUikZGg4PuPFTdX0L8fzvSFvPzOIV2M9nacuAsLSybwr0oyxjTtESlxiZDddCOqP2wA==
  to report this email as spam.

This e-mail and the information, including any attachments it contains, are 
intended to be a confidential communication only to the person or entity to 
whom it is addressed and may contain information that is privileged. If the 
reader of this message is not the intended recipient, you are hereby notified 
that any dissemination, distribution or copying of this communication is 
strictly prohibited. If you have received this communication in error, please 
immediately notify the sender and destroy the original message.

Thank you.

Please consider the environment before printing this email.

-- 
You received this message because you are subscribed to the Google Groups 
"Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to