jenkins - 如何修复——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"
}
}
}
}
}
}
解决方案
我认为您的问题来自您不能stage
在 Groovy Post Build Action 中使用方法这一事实。此方法仅在管道脚本中可用。
推荐阅读
- amazon-web-services - 为 Classic Load Balancer 启用访问日志:存储桶未出现在控制台中
- mongodb - Mongodb 聚合管道 $group 并将带有键/值对的对象返回到结果组
- installation - 执行“sudo kata-runtime kata-check”时,显示“文件 /usr/share/kata-containers/vmlinuz.container 不存在”
- php - Bootstrap 4无法将列放在同一行中
- html - div 导致下一部分不可见
- c# - 启动程序时如何从 MySQL 读取数据并实时显示在 C# 标签中?
- ios - Xcode Swift 委托,新值在 VC 实例化时被覆盖
- node.js - 在 discord.js 中编辑画布附件
- css - scss个别部分不更新实时服务器中的更改
- php - 带有数据属性的 simple_html_dom 解析问题