【问题标题】:How to Fix -- Jenkins Post-build Action Groovy script fails to evaluate如何修复——Jenkins Post-build Action Groovy 脚本无法评估
【发布时间】:2019-05-20 14:52:25
【问题描述】:

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

groovy.lang.MissingMethodException:没有方法签名:Script1.stage() 适用于参数类型:(org.codehaus.groovy.runtime.GStringImpl, Script1$_run_closure1) 值:[branch_1, Script1$_run_closure1@7e39737b ] 可能的解决方案:org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:58) 处的 wait()、any()、isCase(java.lang.Object)

这是我的代码:

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"
                    }
                }     
            }
        }
    }
}

【问题讨论】:

  • 你能给我们更多的信息吗?就像构建后操作的配置(我假设使用 Groovy Posybuild 插件)和错误的完整堆栈跟踪。
  • groovy.lang.MissingMethodException:没有方法签名:Script1.stage() 适用于参数类型:(org.codehaus.groovy.runtime.GStringImpl, Script1$_run_closure1) 值:[branch_1, Script1$_run_closure1@7e39737b] 可能的解决方案:org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:58) 处的 wait()、any()、isCase(java.lang.Object)
  • 请编辑问题,而不是在 cmets 中添加更多信息。
  • 相同的全局变量不可用,我不使用管道,所以我无法测试,但您可能需要执行类似import hudson.model.* 和def build = Thread.currentThread().executable 之类的操作或获取阶段/分支/节点/sshagent 来自某个地方的对象。

标签: jenkins groovy post-build


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2021-04-27
    • 2017-10-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多