Stop a build with a failure status (server side plugin, SRunningBuild)
I develop a server-side plugin and I need to be able to stop a build in a similar way the agent side plugin stops the build (Terminates execution of the build at the current build stage. Build will be stopped with error and given reason. Build will not be marked as canceled.)
SRunningBuild has 2 methods - stop and setInterrupted, I tried both (combination also), but it always ends up with a build marked as canceled.
There is older answer by for a similar question, but it's already outdated
Thank you.
Please sign in to leave a comment.
Hi, there is no way to stop a build on the server and not mark it as canceled. Could you please clarify the use case?
Thank you Dmitry for the fast response.
I develop a plugin which stops a build if the last VCSs commits are not verified with a signature.
If the build is marked as cancelled then it disappears from the Project view (it can be found only via Build History) and it can be very confusing for the user. I would like to preserve it there, like a regular failed build.
@Dmitry isn't there some trick using internal Ex classes as well? I suppose the code must be there, because agent-side plugin is able to do that.
Thanks, then I guess you can stop the build on an agent, right? You can subscribe on the AgentLifeCycleListener.preparationFinished event, do the check and call AgentRunningBuild.stop if needed.
My first implementation was designed for the agent-side (and it worked as you mentioned), but the agent side has one big disadvantage - problem with secrets. We have to be able to hide GIT access token and not to be able to extract it via any build code on the agent (technically you can create a shell build step to read anything you want). Therefore I moved the code to the server side (it also solved my problem with server-side checkouts). The cancelled/failure build status is the only problem I have now.
Thanks, could you please clarify the issue with the Git token? How do you pass this token to the agent?
I know about 2 possibilities how to get the value:
Both can be read by potential harmful building code.
The best way is to avoid a chance to read such token => server plugin side.
so, still no workaround through internal Ex classes?
There is "RunningBuildEx.stopNoInterrupt" method which you can try to use, but it's a part of closed API and can be changed/removed any time
I don't see how these parameters can be read by builds. I mean, you can add the Git token as a password parameter to your project and then use it inside of your plugin, in this case, the parameter won't be passed to the build process
thank you, I give it a try.
Consider this BuildStep - it can read property which is marked as password&hidden (+export file as an artifact)
Oh, yes, you are right
Using Ex class worked, thank you.