How can I modify the Load Balancing behavior Jenkins uses to control slaves?

We were facing a similar issue. So I've put together a plugin that changes the Load Balancer in Jenkins to select a node that currently has the least load - https://plugins.jenkins.io/leastload/

Any feedback is appreciated.


If your build machines cannot comfortably handle more than 1 build, why configure them with 12 executors? If that is indeed the case, you should reduce the number of executors to 1. My Jenkins has 30 slaves, each with 1 executor.


If you do not find a plugin that does it automatically, here's an idea of what you can do:

  • Install Node Label Parameter plugin

  • Add SLAVE parameter to your jobs

  • Restrict jobs to run on ${SLAVE}

  • Add a trigger job that will do the following:

    • Analyze load distribution via a System Groovy Script and decide on which node to start next build.
    • Dispatch the build on that node with Parameterized Trigger plugin by assigning appropriate value to SLAVE parameter.

In order to analyze load distribution you need to install Groovy plugin and familiarize yourself with Jenkins Main Module API. Here are some useful initial pointers.