我创建了一个Groovy脚本,它用于Jenkins作业中的System Groovy Script
步骤,需要访问当前作业的当前构建。
在使用Hudson.model Cause.UpstreamCause
将当前作业的当前构建链接到我正在调度的依赖作业时,需要当前构建。
由于代码更加简洁:
my-job-step.groovy
:
def scheduleDependentJob(jobName) {
def fooParam = new StringParameterValue('foo', 'bar');
def paramsAction = new ParametersAction(fooParam)
println "Scheduling dependent job"
def currentJob = ???
def cause = new Cause.UpstreamCause(currentBuild)
def causeAction = new hudson.model.CauseAction(cause)
instance.queue.schedule(job, 0, causeAction, paramsAction)
}
CauseAction
构造函数(在 http://javadoc.jenkins-ci.org/hudson/model/Cause.UpstreamCause.html 上看到)需要一个 Run
对象,当前的构建对象应该是其实例。我只是找不到在 Groovy 脚本中获取当前运行作业构建的好方法。