On Monday, March 19, 2018 at 5:21:04 PM UTC+1, Ullrich Hafner wrote:
>
> You can detect if the build has been aborted by
> accessing Thread.interrupted() or Thread.currentThread().isInterrupted();
> But your long running task needs to check this...
>
Thanks for your quick response Ullrich. Unfortunately, I tried it before
sending my message to the list and it didn't work. Sample code snippet -
Groovy Postbuild:
<CODE>
int i=0
while (true) {
if (++i > 20) { //to do not create a zombie build :)
manager.listener.logger.println "Timeout. Aborting..."
break
}
if (Thread.currentThread().isInterrupted()) {
manager.listener.logger.println "Interrupted. Aborting..."
break
}
manager.listener.logger.println "Not aborted - ${manager.getResult()} -
${Thread.currentThread().isInterrupted()}"
sleep(1000)
}
</CODE>
As a result I have:
<OUTPUT>
Not aborted - SUCCESS - false
Not aborted - SUCCESS - false
(...)
Not aborted - SUCCESS - false
Timeout. Aborting...
</OUTPUT>
I tested it also with the Groovy system script and the result is the same.
I'm unable to detect if an abort was requested. It's somehow a limitation
if you wait for some external event in the Groovy script.
Is it the same thread? Is there any other way to check if an abort was
requested?
Marcin
>
> Am 19.03.2018 um 16:54 schrieb Marcin Zajączkowski <[email protected]
> <javascript:>>:
>
> Hi,
>
> In the Groovy Postbuild plugin I call an external service in a loop
> waiting for some other operation to finish. It works, however, the build
> ignores a try to abort it using the Jenkins UI or an API.
>
> I tried to check if the current thread isn't interupted
> (Thread.currentThread().isInterrupted()), but it's not. The build results
> (manager.getResult()) is also SUCCESS.
>
> How can I programatically detect (probably using some Jenkins API) that it
> was requested to abort a build to break my loop and allow the build to be
> aborted?
>
> Marcin
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Jenkins Developers" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected] <javascript:>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/jenkinsci-dev/974664bf-1e64-411c-9e19-19a64304b86b%40googlegroups.com
>
> <https://groups.google.com/d/msgid/jenkinsci-dev/974664bf-1e64-411c-9e19-19a64304b86b%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
>
>
--
You received this message because you are subscribed to the Google Groups
"Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/jenkinsci-dev/9527fea0-3356-4e75-beb1-942b8cdd77ab%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.