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!

On Thursday, 8 September 2016 18:10:44 UTC+2, Baptiste Mathus wrote:
>
> 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
>
> Le 6 sept. 2016 6:32 PM, "Adri CS" <acsa...@gmail.com <javascript:>> a 
> Ă©crit :
>
>> 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!
>>
>> -- 
>> 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-use...@googlegroups.com <javascript:>.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/jenkinsci-users/832ce598-477c-4fcf-ae79-4107ee2373d7%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/jenkinsci-users/832ce598-477c-4fcf-ae79-4107ee2373d7%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/6cd0c7ff-c572-4cd1-9755-c52fbbbbaf47%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to