【发布时间】:2021-07-11 09:24:11
【问题描述】:
我有一个如下的闭包,我想从 a、b、c 中获取价值。
#!/usr/bin/env groovy
entry {
a = false
b = "nodejs"
c = "xxx"
}
println entry.a
println entry.b
println entry.c
有什么方法可以实现吗? 我总是收到如下错误
% groovy jenkinsfile.groovy
Caught: groovy.lang.MissingMethodException: No signature of method: jenkinsfile.entry() is applicable for argument types: (jenkinsfile$_run_closure1) values: [jenkinsfile$_run_closure1@12aba8be]
Possible solutions: every(), every(groovy.lang.Closure), any(), any(groovy.lang.Closure), notify(), identity(groovy.lang.Closure)
groovy.lang.MissingMethodException: No signature of method: jenkinsfile.entry() is applicable for argument types: (jenkinsfile$_run_closure1) values: [jenkinsfile$_run_closure1@12aba8be]
Possible solutions: every(), every(groovy.lang.Closure), any(), any(groovy.lang.Closure), notify(), identity(groovy.lang.Closure)
at jenkinsfile.run(jenkinsfile.groovy:2)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
我必须使用这种方式,因为我有很多以这种格式编写的 Jenkinsfile,我想从 Jenkinsfile 中获取值。这是来自 Jenkinsfile 的格式。
【问题讨论】:
-
不,如果你不能或不会改变它是不可能的
-
entry {a=false ...}不是闭包。它看起来像是对一个名为entry的函数的调用,它接受一个参数是一个闭包体,它是{ 和} 之间的块。由于没有定义函数entry,因此您会收到该错误。
标签: groovy closures jenkins-groovy