How to add support for InterruptedException to a plugin?

31 views
Skip to first unread message

Daniel Anechitoaie

unread,
Aug 28, 2017, 8:00:42 AM8/28/17
to Jenkins Developers
Hi,

Any idea how can I add support for InterruptedException to my plugin?
I have a builder plugin that zips some files from the workspace and then uploads them on a remote server.

The flow is basically like this:

---
public void perform(@Nonnull Run<?, ?> build, @Nonnull FilePath workspace,
                        @Nonnull Launcher launcher, @Nonnull TaskListener listener) throws IOException {

    launcher.getChannel().call(deployCallable);
}
---

deployCallable is an instance of a inner class described bellow:

---
private static class DeployCallable extends MasterToSlaveCallable<Boolean, InterruptedException> { // So it works in master/slave setup

        private static final long serialVersionUID = 1L;

        public Boolean call() throws InterruptedException {
               for folder in path {
                      zip(folder);
               }

               for zip in zipFiles {
                      upload(zip); // Using Apache HTTP Client
               }
        }
}
---


The problem is that that if I click cancel on the job it still runs until by build step is finished and all files are zipped and uploaded and only then it marks the build as aborted.
Is there any way to check from my plugin if the job was aborted and just stop wherever I am in the build?
Let's say I just created the zips and user clicks on cancel, how do I stop here and not also upload all zips?

Thank you.

Jesse Glick

unread,
Aug 28, 2017, 8:19:12 AM8/28/17
to Jenkins Dev
On Mon, Aug 28, 2017 at 8:00 AM, Daniel Anechitoaie
<danie...@gmail.com> wrote:
> The problem is that that if I click cancel on the job it still runs until by
> build step is finished and all files are zipped and uploaded and only then
> it marks the build as aborted.
> Is there any way to check from my plugin if the job was aborted and just
> stop wherever I am in the build?

I do not think so. Sounds like an RFE for Jenkins core / Remoting:
interrupting a synchronous remote call should `Thread.interrupt` the
corresponding thread on the remote side.

Daniel Anechitoaie

unread,
Aug 28, 2017, 9:53:45 AM8/28/17
to Jenkins Developers
How do I create a request for enhancement for Jenkins?
I can try and do this and hopefully someone that has experience will implement it at some point, but not sore where and how to create this RFE.

Denys Digtiar

unread,
Sep 3, 2017, 9:10:39 PM9/3/17
to Jenkins Developers
You can refer to https://wiki.jenkins.io/display/JENKINS/How+to+report+an+issue to learn about the process.

Daniel Anechitoaie

unread,
Sep 7, 2017, 2:57:55 AM9/7/17
to Jenkins Developers
Thanks.
Reply all
Reply to author
Forward
0 new messages