Access build duration inside declarative pipeline

613 views
Skip to first unread message

Nick Le Mouton

unread,
Mar 20, 2017, 6:41:01 PM3/20/17
to Jenkins Users
Hi,

My current jobs use the Slack plugin which notifies a channel when a build completes, e.g. job name - #2423 Success after 1 min 49 sec. I'm trying to replicate the same message in declarative pipelines, but I can't seem to find a way to get the build duration. I have tried using currentBuild.duration (which ends up evaluating to 0) and tried currentBuild.rawBuild.getDurationString(), but Jenkins throws an error about not being able to run functions from this context.

How can I get this to work?

Thanks

Andrew Bayer

unread,
Mar 20, 2017, 9:12:07 PM3/20/17
to jenkins...@googlegroups.com
This is more of a general Pipeline matter than just Declarative, fwiw. I've opened https://issues.jenkins-ci.org/browse/JENKINS-42952 for this and will get a PR up shortly.

A.

--
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 jenkinsci-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/9f994a50-f671-42fe-ac77-b75a608daa53%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Andrew Bayer

unread,
Mar 20, 2017, 9:19:18 PM3/20/17
to jenkins...@googlegroups.com

Nick Le Mouton

unread,
Mar 21, 2017, 4:56:02 PM3/21/17
to Jenkins Users
Thanks Andrew, looks good. So with this patch currentBuild.duration should be non 0 and there should be currentBuild.durationString, is that correct?

Nick


On Tuesday, March 21, 2017 at 2:19:18 PM UTC+13, Andrew Bayer wrote:
On Mon, Mar 20, 2017 at 6:11 PM, Andrew Bayer <andrew...@gmail.com> wrote:
This is more of a general Pipeline matter than just Declarative, fwiw. I've opened https://issues.jenkins-ci.org/browse/JENKINS-42952 for this and will get a PR up shortly.

A.
On Mar 20, 2017 15:41, "Nick Le Mouton" <nick.l...@gmail.com> wrote:
Hi,

My current jobs use the Slack plugin which notifies a channel when a build completes, e.g. job name - #2423 Success after 1 min 49 sec. I'm trying to replicate the same message in declarative pipelines, but I can't seem to find a way to get the build duration. I have tried using currentBuild.duration (which ends up evaluating to 0) and tried currentBuild.rawBuild.getDurationString(), but Jenkins throws an error about not being able to run functions from this context.

How can I get this to work?

Thanks

--
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 jenkinsci-use...@googlegroups.com.

Andrew Bayer

unread,
Mar 21, 2017, 6:39:10 PM3/21/17
to jenkins...@googlegroups.com
Correct!

A.

To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/04047271-1d52-4113-890c-6fe21a0649d7%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages