通过循环启动多个 Jenkins 作业
Start multiple Jenkins jobs by loop
我想从一个名为 nightly 的工作开始另一个 Jenkins 工作。我已经创建了一个 for 循环,但我的问题是循环 运行 只执行了一次然后就结束了。
这是我的代码:
stage('Build_Nightly')
{
devices = [
'device1',
'device2',
'device3'
]
for (int i = 0; i < devices.size(); i++) {
build job: 'Build_Daily',
parameters:
[
[$class: 'StringParameterValue', name: 'Device', value: devices[i]]]
],
wait: true
}
}
第一个 运行 成功,没有第二个 运行 与设备 2
中的 propagate
属性
propagate
(optional).
If enabled (default state), then the result of this step is that of the downstream build (e.g., success, unstable, failure, not built, or aborted). If disabled, then this step succeeds even if the downstream build is unstable, failed, etc.; use the result property of the return value as needed.
默认情况下,propagate
设置为 true,这意味着如果下游构建失败,则该步骤将抛出异常,从而使调用者作业失败。如果你想 运行 所有工作而不考虑结果,你可以将 propagate
属性作为 false
.
传递
如果您确实需要保存下游构建的结果,那么 build
命令的返回值包含 result
属性 以及下游作业结果,您可以将其用于任何逻辑你要
示例:
stage('Build_Nightly') {
devices = ['device1', 'device2', 'device3']
devices.each { device ->
def buildResults = build job: 'Build_Daily', wait: true, propagate: false,
parameters:[string(name: 'Device', defaultValue: device, description: '', trim: true)]
println "The result of the downstream job is: ${buildResults.result}"
}
}
我想从一个名为 nightly 的工作开始另一个 Jenkins 工作。我已经创建了一个 for 循环,但我的问题是循环 运行 只执行了一次然后就结束了。
这是我的代码:
stage('Build_Nightly')
{
devices = [
'device1',
'device2',
'device3'
]
for (int i = 0; i < devices.size(); i++) {
build job: 'Build_Daily',
parameters:
[
[$class: 'StringParameterValue', name: 'Device', value: devices[i]]]
],
wait: true
}
}
第一个 运行 成功,没有第二个 运行 与设备 2
propagate
属性
propagate
(optional).
If enabled (default state), then the result of this step is that of the downstream build (e.g., success, unstable, failure, not built, or aborted). If disabled, then this step succeeds even if the downstream build is unstable, failed, etc.; use the result property of the return value as needed.
默认情况下,propagate
设置为 true,这意味着如果下游构建失败,则该步骤将抛出异常,从而使调用者作业失败。如果你想 运行 所有工作而不考虑结果,你可以将 propagate
属性作为 false
.
传递
如果您确实需要保存下游构建的结果,那么 build
命令的返回值包含 result
属性 以及下游作业结果,您可以将其用于任何逻辑你要
示例:
stage('Build_Nightly') {
devices = ['device1', 'device2', 'device3']
devices.each { device ->
def buildResults = build job: 'Build_Daily', wait: true, propagate: false,
parameters:[string(name: 'Device', defaultValue: device, description: '', trim: true)]
println "The result of the downstream job is: ${buildResults.result}"
}
}