Execute action on build deletion

30 views
Skip to first unread message

Adri CS

unread,
Sep 6, 2016, 12:32:41 PM9/6/16
to Jenkins Users
Hi,

I have a parametrized job that spawns Docker containers when it's running. This job is configured to store only the 10 most recent runs.
I would like to have the containers running for as long as the run that spawned them is stored in Jenkins.

So, the idea would be having something like a Listener that would execute the Docker commands to remove the containers when the build is about to be deleted.

I've thought of using the PostBuild Groovy script plugin to execute a listener and redefine the onDeleted method.

For example:

import hudson.model.Run;
import hudson.model.listeners.RunListener;
import hudson.Extension;

@Extension
public class DeleteListener extends RunListener<Run> {
     
@Override
     
void onDeleted(Run r) {
         println
(r.getNumber())
     
}
}



The problem with this approach is that when I execute the build, I get this error:

Groovy script failed:
org
.codehaus.groovy.runtime.metaclass.MissingMethodExceptionNoStack: No signature of method: DeleteListener.main() is applicable for argument types: ([Ljava.lang.String;) values: [[]]
Possible solutions: wait(), wait(long), all(), any(), find(), wait(long, int)



I'm not proficient with Java, neither Groovy; so I'm having a hard time understanding this error.

My question is how, if possible, can I execute some system commands whenever a certain build is about to be deleted.

Thanks and kind regards!

Baptiste Mathus

unread,
Sep 8, 2016, 12:10:44 PM9/8/16
to jenkins...@googlegroups.com

I think this is a matter of context. That has to be like a "system" groovy script.

Also, if that doesn't work, you should probably just create a plugin. You have already written what you need, and that will let you manage it cleanlier (writing tests, versioning…).

Cheers


--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/832ce598-477c-4fcf-ae79-4107ee2373d7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Adri CS

unread,
Oct 13, 2016, 9:34:16 AM10/13/16
to Jenkins Users, m...@batmat.net
Hi Baptiste,

Thanks for your input.
I will go for the plugin option, as I think this shouldn't be a "system" script, because I only need this behaviour for a very specific jobs.

Thanks and cheers!
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages