ele*_*ent 6 groovy enums shared-libraries jenkins jenkins-pipeline
我通过詹金斯管道(共享库)运行此代码。
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")
}
}
Run Code Online (Sandbox Code Playgroud)
它在本地工作,但是在詹金斯管道中,出现此错误:
hudson.remoting.ProxyException:
com.cloudbees.groovy.cps.impl.CpsCallableInvocation
Run Code Online (Sandbox Code Playgroud)
请帮帮我
那个 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()
Run Code Online (Sandbox Code Playgroud)
这个脚本的输出是:
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
Run Code Online (Sandbox Code Playgroud)
问题出在这个字符串中this.t1 = t2.getT2()。事实证明,该t2.getT2()函数无法在构造函数中完成:(
第二个 - 如果你尝试像这样返回:
def getT1() {
wfs.echo 'getT1()'
return t1.toString()
}
Run Code Online (Sandbox Code Playgroud)
会失败...
| 归档时间: |
|
| 查看次数: |
4323 次 |
| 最近记录: |