(replies inline)

On Mon, 12 Mar 2018, Edd Grant wrote:

> Hi folks,
> I'm using the init hook script mechanism ($JENKINS_HOME/init.groovy.d) to 
> programmatically configure Jenkins. I'm building up quite a library of code 
> and want to split it out in to re-usable classes, to keep things 
> maintainable and make it easier to write well focused tests etc. I have 
> tried the following with no luck:
> 1: Trying to split classes out in to separate scripts and using Groovy's 
> 'evaluate' function to load the classes from each script (basically trying 
> to re-implement some sort of importing behaviour). This doesn't work at all 
> due to the way Groovy manipulates scripts.
> 2: Putting my classes in a jar file and adding this to WEB-INF/lib in the 
> Jenkins war. This approach leads to classloader errors, presumably because 
> the jar classloader that my code belongs to doesn't have access to Jenkins' 
> PluginManager 'uberClassLoader'?  
> 3: Same as [2] but adding the jar to the JVM's classpath rather than adding 
> it to the jar. Same result as [2].
> Has anyone tried doing anything similar to this before? I'm really keen to 
> be able to do things like organise my code in packages and keep it in small 
> maintainable units. Grateful for any suggestions.

I have nothing to suggest that will help you refactor those Groovy scripts. As
one who has wielded plenty of init.groovy.d scripts in my day, I can tell you
I'm going to refactor mine by just deleting them in favor of:

I doubt that helps though :)

- R. Tyler Croy

     Code: <https://github.com/rtyler>
  Chatter: <https://twitter.com/agentdero>
     xmpp: rty...@jabber.org

  % gpg --keyserver keys.gnupg.net --recv-key 1426C7DC3F51E16F

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 
For more options, visit https://groups.google.com/d/optout.

Attachment: signature.asc
Description: PGP signature

Reply via email to