如何修复--Jenkins构建后操作Groovy脚本无法评估

如何修复--Jenkins构建后操作Groovy脚本无法评估,jenkins,groovy,post-build,Jenkins,Groovy,Post Build,我是Groovy新手,正在尝试将Groovy脚本作为Jenkins后期构建操作调用,但每当我运行它时,都会收到“错误:未能评估Groovy脚本”: groovy.lang.MissingMethodException:没有方法:Script1.stage()的签名适用于参数类型:(org.codehaus.groovy.runtime.GStringImpl,Script1$\u run\u closure1)值:[branch\u 1,Script1$\u run_closure1@7e397

我是Groovy新手,正在尝试将Groovy脚本作为Jenkins后期构建操作调用,但每当我运行它时,都会收到“错误:未能评估Groovy脚本”:


groovy.lang.MissingMethodException:没有方法:Script1.stage()的签名适用于参数类型:(org.codehaus.groovy.runtime.GStringImpl,Script1$\u run\u closure1)值:[branch\u 1,Script1$\u run_closure1@7e39737b] 可能的解决方案:wait()、any()、isbase(java.lang.Object)位于org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:58)

这是我的密码:

def warList1= ["one.war", "two.war", "three.war" ]

def branches = [:] 

for (int i = 0; i < 10 ; i++) {
    int index=i, branch = i+1
        stage ("branch_${branch}"){
            branches["branch_${branch}"] = { 
                node {
                    sshagent(credentials : ['someuser-SSH']){
                        sh "scp ${WORKSPACE}/${warList1[index]} someuser@<somefqdn>:/tmp/pscp/dev"
                    }
                }     
            }
        }
    }
}

def warrist1=[“一战”、“二战”、“三战”]
def分支=[:]
对于(int i=0;i<10;i++){
int索引=i,分支=i+1
阶段(“分支${branch}”){
分支[“分支${branch}”]={
节点{
sshagent(凭据:['someuser-SSH']){
sh“scp${WORKSPACE}/${warrist1[index]}someuser@:/tmp/pscp/dev”
}
}     
}
}
}
}

我认为您的问题来自这样一个事实:您不能在Groovy后期构建操作中使用
stage
方法。此方法仅在管道脚本中可用。

能否提供更多信息?与构建后操作的配置(我猜想是使用Groovy Posybuild插件)和error.Groovy.lang.MissingMethodException的完整堆栈跟踪一样:没有方法:Script1.stage()的签名适用于参数类型:(org.codehaus.Groovy.runtime.GStringImpl,Script1$\u run\u closure1)值:[分支机构1,脚本1$\u运行_closure1@7e39737b]可能的解决方案:wait()、any()、isbase(java.lang.Object)位于org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:58)请编辑问题,而不是在注释中添加更多信息。相同的全局变量不可用,我不使用管道,因此无法测试,但您可能需要执行类似于导入hudson.model.*的操作,并且可能需要执行
def build=Thread.currentThread().executable
或从某处获取stage/branchs/node/sshagent对象。