Restrict number of instances of a build in the queue

1.2k views Asked by At

Is it possible to limit the number of instances of a single build configuration in the queue?

When a build is triggered I would like it to be added to the queue but if there are more than x instances of that build on the queue already then the oldest instance of the build in the queue is removed as well as the new instance being added.

Is there a plugin that does this?

2

There are 2 answers

1
jinggoy On

Haven't used this plugin personally, but give it a try. I think it throttles the maximum no. of jobs instances in a given node or globally.

https://wiki.jenkins-ci.org/display/JENKINS/Throttle+Concurrent+Builds+Plugin

0
Zac Thompson On

If you only want one instance in the queue: set the job to be parameterized (e.g., just a bogus boolean parameter with a default value). It considers copies of the same job in the queue to be duplicates if they have the same parameter values, so I don't think it would queue a second one.

If you want to limit the queue size for a given job to some other number, I don't know how; I suspect the right approach would depend on your use case, and if it's unusual enough there might not be a simple solution. (I haven't personally encountered situations where queuing multiple jobs makes sense but only up to some specific number: if you want them queued at all then I suspect you care about all of them. Queue length of 0 or 1 has some obvious applications though.)