Search code examples
jenkinsjenkins-plugins

Is there a way in Jenkins to stop or reduce duplicate jobs?


I have a job that kicks off on any commit. It takes 5-10 minutes to run.

But if (say) 4 or 5 git commits come back-to-back I don't want 4 or 5 jobs run - just one job for the last commit. So basically if there is a job of type "X" in the build queue I don't want another job of type "X" in the queue.


Solution

  • That should be the default behavior if you're using the SCM trigger, default job parameters, and don't check the 'Execute concurrent builds if necessary' option.

    1. First job is going to queue and run immediately.
    2. On source change, next job is going to queue and wait until first one is complete.
    3. A third SCM change would detect job already in queue and not do anything.
    4. When first job is done, next one will start - and will use whatever is in the SCM at the moment it starts (not the moment it was scheduled).

    That behavior can be changed using parameters, concurrent builds, job throttling, etc. My knowledge there might also be outdated (Jenkins is evolving pretty fast).

    On a side note: multiple builds are not necessarily a bad thing - they give you failure locality, which might allow you faster identification of the offending commit. It doesn't matter much for 10 minutes builds, but if your build grows larger than that it can be a problem (with a large team, you can have a LOT of commits in 30 minutes).