Gracefully stopping a build step (plugin) on build abort

倖福魔咒の 提交于 2019-12-10 01:16:29

问题


I have a plugin in Jenkins that operates a remote server via rest.
How can I send one last request to the server on build abort? Thus, gracefully finishing the work of the plugin?

The only reference to the 'Abort sequence' that I found is this. Which makes me think that the procedure is very rough, and that I can't catch the signal before it terminates the child (my plugin).


回答1:


I have a similar need, which I solved with the PostBuildScript Plugin.

I choose to run a build step, but you can run several other options. Very easy to use. I have a script I must run regardless of how the build ended (success, fail or abort). It works great for me.

I hope this helps.




回答2:


When the build is aborted, an InterruptedException is thrown. You can catch it like any other exception, and not only gracefully exit, but prevent the abort, if you so wish.

In your boolean perform() method, set up a

try {
 ... // Whatever your plugin does
}
catch (InterruptedException e) {
    // Code to handle build being aborted.
}

statement, which will handle any aborts that occur while your build step is being run. In the catch statement you can then throw an InterruptedException again to continue aborting the build, or just return and let the build continue.



来源:https://stackoverflow.com/questions/14119727/gracefully-stopping-a-build-step-plugin-on-build-abort

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!