I have the following in a groovy file...
// jenkins/Application.groovy
package jenkins
class Application{
String name
Application(name){
this.name = name
}
}
I am trying to import it and I have tried these but none seem to work. These are all in jenkins/Test.groovy
final GroovyScriptEngineImpl engine = (GroovyScriptEngineImpl) this.scriptingEngines.getEngineByName("groovy");
GroovyClassLoader classLoader = engine.getClassLoader();
classLoader.parseClass(new GroovyCodeSource("./jenkins/Application.groovy"))
engine.setClassLoader(classLoader)
This gives..
Script1.groovy: 17: unable to resolve class Application
Then I tried...
// jenkins/Application.groovy
// Added
return { Application }
// jenkins/Test.groovy
app = load "./jenkins/Application.groovy"
def dna = new app.Application("blah")
and I get...
Script1.groovy: 11: unable to resolve class app.Application
How do I import a call in a Jenkins GroovyScript?
Update
I changed my code to the following (and moved into a domain folder)...
app = load "./jenkins/domain/Application.groovy"
def dna = app.newInstance([name:"blah"] as Object[])
When I run I get...
org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: Scripts not permitted to use staticMethod org.codehaus.groovy.runtime.DefaultGroovyMethods newInstance java.lang.Class java.lang.Object[]