-
Improvement
-
Resolution: Unresolved
-
Trivial
-
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")