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.
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.
To do so, first create a new String parameter "JOB_COUNTER" with default value = 1.
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
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:
UPDATE:
Another way to loop, is to decrease JOB_COUNTER in the predefined parameters (instead of inside EnvInject):
JOB_COUNTER=${JOB_COUNTER}-1
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)
And finally, the Conditional action should be:
$JOB_COUNTER > Greater than 1
Well, there is no easy solution for this problem, but it can be easily scripted. And there are couple of ways to do that:
Using a Build Flow Plugin
This plugin will let you script the way that the project build flow is being executed. You can script you builds to run in parallel, to retry the failed builds for as many times as you desire, and much more. I would give it a try and create a script with desired number of retries. I think it'll be your best option to try.
You can try using Fail the Build Plugin and either Retry Failed Builds or Periodic Reincarnation Plugin
It will enable you to break the build on purpose and then the other plugin will try to build it again and again. It will not be easy to control the number of retries here - you would have to change the status of the build based on a variable from script in your build process or something. But hey, maybe it is a solution as well.
More complex solutions you can base on RabbitMQ - you can put more than one message in a queue to build the project numerous times and then build the project based on those messages.
You can base your build on BPM: JBPM Plugin with JBPM Workflow Plugin or Jenkow
I can probably come up with more solutions, but the first one above is probably a good starting point...