gpt4 book ai didi

jenkins 共享库错误 com.cloudbees.groovy.cps.impl.CpsCallableInvocation

转载 作者:行者123 更新时间:2023-12-04 12:27:22 26 4
gpt4 key购买 nike

我通过 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")
}
}

它在本地工作,但在 Jenkins 管道中,我收到此错误:
hudson.remoting.ProxyException:         
com.cloudbees.groovy.cps.impl.CpsCallableInvocation

请帮帮我

最佳答案

那个 Jenkins 中的 groovy 解释器有问题。我正在尝试编写一个库并遇到相同的错误。

我做了一个管道脚本的例子。我编写了不同的类来避免诱发错误:

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()
}

会失败...

关于jenkins 共享库错误 com.cloudbees.groovy.cps.impl.CpsCallableInvocation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51340854/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com