• Icon: Improvement Improvement
    • Resolution: Unresolved
    • Icon: Trivial Trivial
    • groovy-plugin
    • None

      Pass the current "shell" object in the binding to the grovvy script. That would simplify loading and running other groovy scripts from the workspace.

      Currently I'm using

      static loadScriptFromWorkspace(build, fileName, loader=null)
              def scriptFile = build.project.getWorkspace().child(fileName)
              def cl = loader ?: Jenkins.getInstance().getPluginManager().uberClassLoader
              def groovyShell = new GroovyShell(cl)
              return groovyShell.parse(scriptFile.read().newReader())
      }
      

      And this is invoked with

      loadScriptFromWorkspace(build, "foo.groovy", this.class.classLoader)
      

      With a "shell" object, I can skip the classloader part.

      static loadScriptFromWorkspace(groovyShell, fileName)
              build = groovyShell.getVariable("build")
              def scriptFile = build.project.getWorkspace().child(fileName)
              return groovyShell.parse(scriptFile.read().newReader())
      }
      

      to create a new shell, loader is set to loader

      loadScriptFromWorkspace(shell, "foo.groovy")
      

          [JENKINS-34974] Pass shell object to groovy script

          There are no comments yet on this issue.

            vjuranek vjuranek
            axelh Axel Heider
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: