【发布时间】:2023-01-04 05:15:20
【问题描述】:
对不起,菜鸟问题。我是 Groovy 的新手。
我正在使用 groovysh 实用程序调试一些 Jenkins 脚本。 这是一段代码:
println("Start")
List job_params() {
def parameter_list = [
choice(name: 'BAUDRATE',
choices: ['9600', '115200'],
description: 'Baud rate of the device.'),
]
return parameters(parameter_list)
}
params = job_params()
println("End")
当我尝试运行此代码时,我收到错误消息:
groovy:000> :load BExample.gvy
Start
===> null
===> true
ERROR groovy.lang.MissingMethodException:
No signature of method: groovysh_evaluate.choice() is applicable for argument types: (java.util.LinkedHashMap) values: [[name:BAUDRATE, choices:[9600, 115200], description:Baud rate of the device.]]
Possible solutions: collect()
at groovysh_evaluate.job_params (groovysh_evaluate:6)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
我需要“导入”某些东西吗? 我该如何解决这个问题。
顺便说一句,这段代码 sn-p 在 Jenkins 上运行没有错误。
【问题讨论】:
-
Jenkins 有自己的领域特定语言(DSL),它是用 Groovy 开发的,用作脚本。您不能在独立的 Groovy 脚本中使用此 DSL 语法。如果你想使用它,你需要在你的 Groovy 引擎中获取 DSL 库。
-
@HiteshA.Bosamiya 你能澄清一下是否有可能以某种方式“groovysh”某些支持 DSL 的脚本吗?我需要安装一些额外的包吗?
标签: java jenkins groovy jenkins-groovy