注意:管道插件应该使这个问题没有实际意义,但我还没有机会更新我们的基础设施。
启动不带参数的下游作业:
job = manager.hudson.getItem(name)
cause = new hudson.model.Cause.UpstreamCause(manager.build)
causeAction = new hudson.model.CauseAction(cause)
manager.hudson.queue.schedule(job, 0, causeAction)
要使用参数启动下游作业,您必须添加一个ParametersAction
. 假设Job1
有参数A
,C
默认分别为“B”和“D”。IE:
A == "B"
C == "D"
假设Job2
具有相同的 A 和 B 参数,但也采用E
默认为“F”的参数。以下构建后脚本Job1
将复制其A
和C
参数并将参数设置为' 和' 值E
的串联:A
C
params = []
val = ''
manager.build.properties.actions.each {
if (it instanceof hudson.model.ParametersAction) {
it.parameters.each {
value = it.createVariableResolver(manager.build).resolve(it.name)
params += it
val += value
}
}
}
params += new hudson.model.StringParameterValue('E', val)
paramsAction = new hudson.model.ParametersAction(params)
jobName = 'Job2'
job = manager.hudson.getItem(jobName)
cause = new hudson.model.Cause.UpstreamCause(manager.build)
causeAction = new hudson.model.CauseAction(cause)
def waitingItem = manager.hudson.queue.schedule(job, 0, causeAction, paramsAction)
def childFuture = waitingItem.getFuture()
def childBuild = childFuture.get()
hudson.plugins.parameterizedtrigger.BuildInfoExporterAction.addBuildInfoExporterAction(
manager.build, childProjectName, childBuild.number, childBuild.result
)
您必须添加$JENKINS_HOME/plugins/parameterized-trigger/WEB-INF/classes
到 Groovy Postbuild 插件的Additional groovy classpath
.