问题
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