我正在尝试在我的jenkins共享库中实现装饰器模式。 我想装饰' timeout-try-catch '块,因此每当调用某个类的某个方法(装饰器不在乎那个类是那个方法)时,它都会自动包装在 timeout-try-catch 块。 但是为此,我需要重写装饰器类中的方法“ invokeMethod”。这是导致错误的Jenkinsfile中最小的代码段:
node {
sh 'echo "the content"'
new MyClass().doSomething() // output: doSomething
}
class MyClass {
def invokeMethod(String name,args) {
println name
}
}
我得到以下错误: org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedaccessException:脚本不允许使用groovy.lang.GroovyObject invokeMethod java.lang.String java.lang.Object方法(MyClass doSomething)
在不退出Jenkins的“沙盒”模式的情况下,是否有任何方法可以覆盖invokeMethod或实现动态装饰器模式(它并不关心装饰类及其方法)?