I'm getting following exception:
when delegating instance of class to closure in shared library.
In shared library I have file vars/buildPlugin.groovy
and here is how it is using in Jenkinsfile (or pipeline script):
I'm expecting to get following output:
Name from Jenkinsfile: name_from_Jenkinsfile
Name set by closure: name_from_Jenkinsfile
But instead getting the exception above.
1) If uncheck Use Groovy Sandbox checkbox in pipeline job config - I'm getting expected output. But I don't want to disable sandbox or whitelist `method groovy.lang.GroovyObject invokeMethod java.lang.String java.lang.Object`
2) If change `def config = new Foo()` to `def config = [:]` in vars/buildPlugin.groovy I'm getting expected output. But I need to use class for defining additional methods in it.
3) If change `echo` to `this.echo` in Jenkinsfile - I'm getting expected output. But this will require to add `this` in all Jenkinsfiles for all objects not defined in delegated class instance.