我在Jenkins中使用System Groovy脚本来调用另一个作业。 以下是我的代码:
delete_messages
执行此代码时,我无法触发新作业。新作业需要1个参数" BRANCH"。我已经从https://wiki.jenkins.io/display/JENKINS/Groovy+plugin
中引用了这段代码但我收到错误:
def trigger(BRANCH)
{
println "$BRANCH"
println "pppppp"
// Start another job
def job = Hudson.instance.getJob('Step2')
def anotherBuild
try {
def params = [
new StringParameterValue('BRANCH', BRANCH),
]
def future = job.scheduleBuild(0, new Cause.UpstreamCause(build), new ParametersAction(params))
println "Waiting for the completion of " + HyperlinkNote.encodeTo('/' + job.url, job.fullDisplayName)
anotherBuild = future.get()
} catch (CancellationException x) {
throw new AbortException("${job.fullDisplayName} aborted.")
}
println HyperlinkNote.encodeTo('/' + anotherBuild.url, anotherBuild.fullDisplayName) + " completed. Result was " + anotherBuild.result
// Check that it succeeded
build.result = anotherBuild.result
if (anotherBuild.result != Result.SUCCESS && anotherBuild.result != Result.UNSTABLE) {
// We abort this build right here and now.
throw new AbortException("${anotherBuild.fullDisplayName} failed.")
}
}