我创建了一个 Groovy 脚本,用于System Groovy Script
Jenkins 作业中需要访问当前作业的当前版本的步骤。
使用 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)
}
The CauseAction
构造函数(见http://javadoc.jenkins-ci.org/hudson/model/Cause.UpstreamCause.html http://javadoc.jenkins-ci.org/hudson/model/Cause.UpstreamCause.html)需要一个Run
对象,当前构建对象应该是其实例。我只是找不到一种好方法来在 Groovy 脚本中构建当前正在运行的作业。
如果您在 Jenkins 工作中使用Groovy 插件 https://wiki.jenkins-ci.org/display/JENKINS/Groovy+plugin,然后在里面Execute system Groovy script
步骤该插件已经允许您访问一些预定义的变量:
build
The current AbstractBuild.
launcher
A Launcher.
listener
A BuildListener.
out
A PrintStream (listener.logger).
例如:
println build.getClass()
Outputs:
class hudson.model.FreeStyleBuild
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)