在Jenkins中重复构建n次 [英] Repeat build n times in Jenkins

查看:542
本文介绍了在Jenkins中重复构建n次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以重复构建N次吗? (与上次构建的状态无关).构建是经过参数化的,目前,我正在使用Jenkins Parameterized Trigger插件,该插件设置为触发相同的构建,但这当然是一个无限循环.

Is there any way to repeat a build N times? (doesn't matter the status of the last build). The build is parametrized and for the moment I am using Jenkins Parameterized Trigger plugin which is set to trigger the same build, but this is of course an infinite loop.

我希望能够指定重复多少次使用相同的参数进行构建.

I would like to be able to specify how many times to repeat the build with the same parameters.

推荐答案

可以通过添加评估 $ JOB_COUNTER 的条件步骤来创建Jenkins作业的重复循环(不是无限循环) >参数,只需在每次迭代中减少.

It is possible to create a repeated loop (not infinite) of a Jenkins job, by adding a conditional step that evaluates a $JOB_COUNTER parameter, which simply being decreased on each iteration.

为此,请首先创建一个默认值为1的新String参数"JOB_COUNTER".

To do so, first create a new String parameter "JOB_COUNTER" with default value = 1.

然后使用 EnvInject插件,然后选中"准备运行环境"和"覆盖构建参数",并添加" Evaluated Groovy脚本":

Then use EnvInject plugin, and check "Prepare an environment for the run" + "Override Build Parameters", and add in "Evaluated Groovy script":

def map  = [:]
int newJobCounter = JOB_COUNTER.toInteger() - 1
println "Decreasing JOB_COUNTER from " + JOB_COUNTER + " to " + newJobCounter  
map.put("JOB_COUNTER", newJobCounter)
return map

最后,使用条件BuildStep插件 + 参数化触发器插件(以及可选的

Finally, with Conditional BuildStep plugin + Parameterized Trigger plugin (and optionally with PostBuildScript plugin, if you'd like to start next iteration only after build has completed), set the following:

更新:

另一种循环方法是减少预定义参数(而不是EnvInject内部)中的JOB_COUNTER:

Another way to loop, is to decrease JOB_COUNTER in the predefined parameters (instead of inside EnvInject):

JOB_COUNTER=${JOB_COUNTER}-1

然后,要在每次迭代中正确更新JOB_COUNTER,请在EnvInject常规中使用评价()方法而不是toInteger():

Then, to correctly update JOB_COUNTER on each iteration, use evaluate() method instead of toInteger(), in the EnvInject groovy:

int newJobCounter = evaluate(JOB_COUNTER)
println "Evaluating JOB_COUNTER: " + JOB_COUNTER + " => " + newJobCounter  
map.put("JOB_COUNTER", newJobCounter)

最后,条件操作应为:

$JOB_COUNTER > Greater than 1

这篇关于在Jenkins中重复构建n次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆