jenkins - 出现 FATAL : No signature of method: hudson. model.FreeStyleBuild.call() 错误

标签 jenkins groovy

我正在尝试在 Jenkins groovy 脚本中执行以下命令。

import hudson.model.*

def buildA = build("Master-Build")
println(buildA.getProject().getLastSuccessfulBuild()) 

我收到以下错误

00:00:00.652 FATAL: No signature of method: hudson.model.FreeStyleBuild.call() is applicable for argument types: (java.lang.String) values: [Master-Build] 00:00:00.652 Possible solutions: wait(), save(), any(), wait(long), each(groovy.lang.Closure), any(groovy.lang.Closure) 00:00:00.652 groovy.lang.MissingMethodException: No signature of method: hudson.model.FreeStyleBuild.call() is applicable for argument types: (java.lang.String) values: [Master-Build]

我该如何解决这个问题?

最佳答案

查看错误,您似乎正在自由式构建中调用执行系统 ​​Groovy 脚本 构建步骤。当您在该步骤中使用 groovy 时,变量 build 被预定义为当前构建,而不是用于构建其他作业的函数(您可能会将其与构建流程作业中的预定义函数/变量混淆,其中build 变量是一个启动新构建的函数。

因此,为了开始新的构建,您需要直接访问 Jenkins 实例并告诉它开始新作业 ( inspired by this script ):

// Import Jenkins
import jenkins.model.Jenkins;
// Get Jenkins instance
def j = Jenkins.getInstance();
// Get the job we wan't to trigger
def job = j.getItem("B");
// Finally we schedule a new build which starts directly (the zero in the argument)
job.scheduleBuild2(0)

关于jenkins - 出现 FATAL : No signature of method: hudson. model.FreeStyleBuild.call() 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42109441/

相关文章:

ios - 使用分发条款退出应用程序

java - 在 Jenkins 插件中设置 envvars

Groovy + Antbuilder : How to use Grape to with taskdef?

java - 调试使用 Spock 和 JMockit 测试的 Java 代码

Groovy:如何记住闭包在两次执行之间的变量值?

mysql - Groovy withBatch 真的很慢

java - 如何使用gradle API检查工件的存在?

jenkins - 在 Kubernetes 上的 Jenkins 中安装卷

Jenkins 插件通过 https 远程下载文件

javascript - 在 jelly 脚本中使用 JavaScript