Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-6068

Classloader for actual System Groovy script and plugin "Execute system Groovy script" is not the same

    XMLWordPrintable

Details

    • Bug
    • Status: Resolved (View Workflow)
    • Major
    • Resolution: Fixed
    • groovy-plugin
    • None
    • Hudson 1.352
      Groovy plugin 1.4

    Description

      The following code works if you execute it on the Hudson script page (hudsonserver/script), but not if you execute it as a "Execute system Groovy script" build step:

      import hudson.scm.SubversionSCM
      println(SubversionSCM.class)

      Running under my hudson, it produces a ClassNotFoundException when run as a "Execute system Groovy script" build step. SubversionSCM is a class that's supplied by the Subversion plugin.

      It turns out that the classloader handed to the Groovy script from the script page is not the same as that which it gets from the build step. The script page appears to use PluginManager.uberClassLoader, which knows where all of the plugin classes are. The Groovy plugin build step appears to use a different classloader, that only knows about the core libraries.

      Right now, to use any classes delivered by plugins, you have to do the following (in this case for SubversionSCM):
      Class.forName("hudson.scm.SubversionSCM", true, hudson.model.Hudson.instance.getPluginManager().uberClassLoader)
      You can then use the class, but it requires all kinds of ugly reflection code and is generally a pain compared to the normal way.

      I think it would be better if the build step offered the same classpath as the script page, so that anything that you develop on the script page can be used in your build without modification.

      I haven't dug into the code, but I'm assuming the fix for this involves handing PluginManager.uberClassLoader to the "Execute system Groovy script" build step.

      Attachments

        Issue Links

          Activity

            vjuranek vjuranek added a comment -

            Fix, will be in next release

            vjuranek vjuranek added a comment - Fix, will be in next release

            Code changed in hudson
            User: : vjuranek
            Path:
            trunk/hudson/plugins/groovy/src/main/java/hudson/plugins/groovy/SystemGroovy.java
            http://jenkins-ci.org/commit/36820
            Log:
            Add class loader, fix for JENKINS-6068

            scm_issue_link SCM/JIRA link daemon added a comment - Code changed in hudson User: : vjuranek Path: trunk/hudson/plugins/groovy/src/main/java/hudson/plugins/groovy/SystemGroovy.java http://jenkins-ci.org/commit/36820 Log: Add class loader, fix for JENKINS-6068

            People

              vjuranek vjuranek
              lotus118 lotus118
              Votes:
              3 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: