【发布时间】:2019-01-01 15:29:30
【问题描述】:
我是 Jenkins/Groovy 的新手,请多多包涵。
我正在使用管道 groovy 脚本中的 DSL。 DSL 实例化了一个尝试使用 Jenkins 插件的自定义类。我不断收到错误,好像系统正试图以类的直接成员身份访问插件...?
Jenkins 工作:流水线脚本
@Library('lib-jenkins-util@branchname') _ // contains dsl.groovy
dsl {
x = 'value'
}
文件:dsl.groovy
def call(body) {
def config = [:]
body.resolveStrategy = Closure.DELEGATE_FIRST
body.delegate = config
body()
node('node-name') {
stage('Stage 1') {
def f = new Foo()
}
}
文件:Foo.groovy
class Foo implements Serializable {
Foo() {
// fails below
sh "curl http://our-jenkins-server/xxx/api/json -user username:apitoken -o output.json"
json = readJSON file: output.json
}
}
错误:
hudson.remoting.ProxyException: groovy.lang.MissingMethodException: 否 方法签名: com.xxx.Foo.sh() 是 适用于参数类型: (org.codehaus.groovy.runtime.GStringImpl) 值:[curl http://our-jenkins-server/xxx/api/json -user username:apitoken -o output.json]
有人可以帮助我了解我缺少什么吗?是不是不能在自定义类中直接调用插件?
【问题讨论】:
标签: class jenkins groovy plugins call