FW: Jenkins init.groovy compilation

43 views
Skip to first unread message

Jason Grammenos

unread,
Dec 15, 2017, 11:43:55 AM12/15/17
to jenkins...@googlegroups.com

 

Hello,

 

I am having an issue with multiple scripts in init.groovy.d, and the scripts failing compilation.

Situation:

There are 2 scripts

  1. The first script installs a bunch of plugins.
  2. Second script sets up authentication

 

The second script depends on plugins installed by script 1  (eg: import com.michelin.cio.hudson.plugins.rolestrategy.*)

Script 1, invokes a Jenkins restart when it is finished.

 

So Jenkins start its init, compiles and runs script 1, and then attempts to compile script 2,

but has not yet completed its restart and doesn’t realise the plugins are installed so Script 2 fails compilation.

The restart completes and all the scripts are run again, this time successfully.

 

Is there any way to prevent this compilation failure?

 

Thank you

Regards

Jason

 

Agility PR Solutions

Jason Grammenos | Operations and Infrastructure Analyst
P: 613.232.7797 | Toll-free: 866.545.3745 
Work hours: Monday-Friday, 8am-4:30pm ET
jason.g...@agilitypr.com
agilitypr.com (formerly MediaMiser)

 

Reinhold Füreder

unread,
Dec 19, 2017, 1:44:50 AM12/19/17
to jenkins...@googlegroups.com

Hi Jason,

 

yes, I remember stumbling over this as well.

 

Partially I have actually uses a workaround for that compilation failure: However, I am not sure it is worth it – because it is based on using reflection, e.g.:

 

def instance = Jenkins.getInstance()

    // LDAPSecurityRealm class depends on "LDAP" plugin => use reflection for creation:

    def ldapSecurityRealmClass = this.class.classLoader.loadClass('hudson.security.LDAPSecurityRealm')

    SecurityRealm ldapRealm = ldapSecurityRealmClass.newInstance(server, rootDN, userSearchBase, userSearch, groupSearchBase, managerDN, managerPassword, inhibitInferRootDN)

    instance.setSecurityRealm(ldapRealm)

    instance.save()

 

 

And later on, IIRC, I mostly “only” relied on the init scripts (one for each responsibility “area”) checking whether or not a restart due to plugin installation/updates is still pending based on a kind of marker file (and ignoring compilation failures):

 

def restartFile = new File(instance.getRootDir(), "JenkinsRestartByInitScript")

if (restartFile.exists()) {

  println "--> Jenkins restart is pending: skipping this hook script"

  return

}

// Here follows the logic like setting up the LDAP security realm…

 

 

HTH -- although this is not a real solution,

                Reinhold

Jason Grammenos

unread,
Dec 19, 2017, 8:24:25 AM12/19/17
to jenkins...@googlegroups.com

Thank you very much Reinhold Füreder

 

I will look into reflection, but probably just choose to ignore the errors and they do not end up causing problems anyways.

And I will consider filling a bug with Jenkins.

 

 

Agility PR Solutions

Jason Grammenos | Operations and Infrastructure Analyst
P: 613.232.7797 | Toll-free: 866.545.3745 
Work hours: Monday-Friday, 8am-4:30pm ET
jason.g...@agilitypr.com
agilitypr.com (formerly MediaMiser)

 

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/AM4P190MB00677F1A1C76C862343A189EF70F0%40AM4P190MB0067.EURP190.PROD.OUTLOOK.COM.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages