Access build duration inside declarative pipeline

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Access build duration inside declarative pipeline

Nick Le Mouton
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 [hidden email].
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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Access build duration inside declarative pipeline

Andrew Bayer
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" <[hidden email]> 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 [hidden email].
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.

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CAPbPdOZ4QiVUEOQpgmbZHkD9LvT%2B7a%3DGUWbHWaQvhvMFZ9wMcA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Access build duration inside declarative pipeline

Andrew Bayer

On Mon, Mar 20, 2017 at 6:11 PM, Andrew Bayer <[hidden email]> 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" <[hidden email]> 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 [hidden email].
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.


--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CAPbPdOYoPq12D6049dp%2BcTEX%2Bu6kkeXE7G7O%3DzihMLi9bbzViQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Access build duration inside declarative pipeline

Nick Le Mouton
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:
And a PR up at <a href="https://github.com/jenkinsci/workflow-support-plugin/pull/33" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fjenkinsci%2Fworkflow-support-plugin%2Fpull%2F33\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGh0y26D5vAstGeTNGwJzic_BSlMQ&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fjenkinsci%2Fworkflow-support-plugin%2Fpull%2F33\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGh0y26D5vAstGeTNGwJzic_BSlMQ&#39;;return true;">https://github.com/jenkinsci/workflow-support-plugin/pull/33

On Mon, Mar 20, 2017 at 6:11 PM, Andrew Bayer <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="AgkyKM5KCAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">andrew...@...> wrote:
This is more of a general Pipeline matter than just Declarative, fwiw. I've opened <a href="https://issues.jenkins-ci.org/browse/JENKINS-42952" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fissues.jenkins-ci.org%2Fbrowse%2FJENKINS-42952\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFoF9FV9lX0KB8-1dARh_nX9-Gc8g&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fissues.jenkins-ci.org%2Fbrowse%2FJENKINS-42952\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFoF9FV9lX0KB8-1dARh_nX9-Gc8g&#39;;return true;">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" <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="AgkyKM5KCAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">nick.l...@...> 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 <a href="javascript:" target="_blank" gdf-obfuscated-mailto="AgkyKM5KCAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/jenkinsci-users/9f994a50-f671-42fe-ac77-b75a608daa53%40googlegroups.com?utm_medium=email&amp;utm_source=footer" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/jenkinsci-users/9f994a50-f671-42fe-ac77-b75a608daa53%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/jenkinsci-users/9f994a50-f671-42fe-ac77-b75a608daa53%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/jenkinsci-users/9f994a50-f671-42fe-ac77-b75a608daa53%40googlegroups.com.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.


--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/04047271-1d52-4113-890c-6fe21a0649d7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Access build duration inside declarative pipeline

Andrew Bayer
Correct!

A.

On Tue, Mar 21, 2017 at 1:56 PM, Nick Le Mouton <[hidden email]> wrote:
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 <[hidden email]> 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" <[hidden email]> 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.
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.


--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/04047271-1d52-4113-890c-6fe21a0649d7%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CAPbPdOadDu8S5cmRD%2BHh5uN%2B23oqY7gQsc%3DRDZo87BrSOP5tAQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Loading...