我通过jenkins管道(共享库)运行此代码。
enum Components {
service('name_api')
Components(String componentName) {
this.componentName = componentName
}
private String componentName
String getComponentName() {
return componentName
}
static boolean isValid(String name) {
for (Components component : values()) {
if (component.getComponentName().equalsIgnoreCase(name)) {
return true
}
}
println("The name of component is incorrect")
}
}
在本地是可行的。我收到此错误:
hudson.remoting.ProxyException:
com.cloudbees.groovy.cps.impl.CpsCallableInvocation
请帮助我
答案 0 :(得分:2)
该詹金斯中的常规解释器出了些问题。我正在尝试编写一个库,并且遇到相同的错误。
我以管道脚本为例。我编写了不同的类以避免引发错误:
class Test1 {
private t1
private wfs
Test1(Test2 t2, wfs) {
this.wfs = wfs
wfs.echo 'TEST1 constructor'
this.t1 = t2.getT2() }
def getT1() {
wfs.echo 'getT1() function'
def result = t1.toString()
return result }
}
class Test2 {
private t2
private wfs
Test2(wfs) {
this.wfs = wfs
wfs.echo 'TEST2 constructor'
this.t2 = "hello" }
def getT2() {
wfs.echo 'getT2() function'
def result = t2.toString()
return result }
}
echo 'Creating Test2 object'
Test2 test2 = new Test2(this)
echo "Test2 object was created successfully. test2.t2="+test2.getT2()
echo 'Creating Test1 object'
Test1 test1 = new Test1(test2,this)
echo "Test1 object was created successfully. test1.t1="+test1.getT1()
此脚本的输出为:
Started by user admin
[Pipeline] echo
Creating Test2 object
[Pipeline] echo
TEST2 constructor
[Pipeline] echo
getT2() function
[Pipeline] echo
Test2 object was created successfully. test2.t2=hello
[Pipeline] echo
Creating Test1 object
[Pipeline] echo
TEST1 constructor
[Pipeline] End of Pipeline
com.cloudbees.groovy.cps.impl.CpsCallableInvocation
Finished: FAILURE
问题出在此字符串this.t1 = t2.getT2()
中。原来t2.getT2()
函数不能在构造函数:(
第二个-如果您尝试像这样返回:
def getT1() {
wfs.echo 'getT1()'
return t1.toString()
}
它将失败...
答案 1 :(得分:0)
由于这是密切相关的,并且会在顶部显示在Google顶部,因此我将向com.cloudbees.groovy.cps.impl.CpsCallableInvocation
当我使用以下构造函数时,我遇到了这个问题:(EclipseIDE在本地没有错误,但是jenkins抱怨此无用的错误消息,没有提及任何代码行)
class blubb{
blubb(Name){
super(Name) // must be first in CONSTRUCTOR
// no return from super! , nevertheless, last throws...
println("This will never be printed inside of jenkins!")
someBaseClassFunction() // this line is not allowed but errors!
}
}
这是@wunt小但超级有用的注释开始起作用的地方。
答案 2 :(得分:0)
遇到此错误时,我用groovy-cps library by Cloudbees中的@NonCPS
注释了失败的方法并解决了!
答案 3 :(得分:0)
我有同样的问题。在我的情况下,这是由对字段的构造函数的参数的方法调用引起的,该方法调用依赖于仅在构造函数中初始化的字段。像这样:
class A {
final def b = new B(method())
final def param
A(param) {
this.param = param
}
def method() {
return param.foo()
}
}
我将初始化移到了构造函数中,并内联了方法,问题消失了:
class A {
final def b
final def param
A(param) {
this.param = param
this.b = new B(param.foo())
}
}