首页 > 解决方案 > 如何修复——Jenkins Post-build Action Groovy 脚本无法评估

问题描述

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

groovy.lang.MissingMethodException:没有方法签名:Script1.stage() 适用于参数类型:(org.codehaus.groovy.runtime.GStringImpl, Script1$_run_closure1) 值:[branch_1, Script1$_run_closure1@7e39737b] 可能的解决方案: wait(), any(), isCase(java.lang.Object) at 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"
                    }
                }     
            }
        }
    }
}

标签: jenkinsgroovypost-build

解决方案


我认为您的问题来自您不能stage在 Groovy Post Build Action 中使用方法这一事实。此方法仅在管道脚本中可用。


推荐阅读