One of the most helpful features of Jenkins CI is automatic queuing of jobs. On a given Jenkins instance, if there are more build jobs requested than there are resources to execute these jobs, the jobs will queue, and Jenkins will handle executing these jobs in the order they were requested. By assigning labels to nodes, you can specify the resources you want to use for specific jobs, and set up graceful queuing of all the jobs for your test runs. This topic will explain how queuing works in Jenkins, and how to set up your nodes and jobs to use labels. It assumes you have access to an admin user account in Jenkins, or at least a user with appropriate administrative rights.
Let’s look at a basic example of how queuing works on Jenkins.
This screenshot shows the administration page for a basic Jenkins instance with a single master node, which is a machine that runs jobs.
The Build Queue and Build Executor Status panels show the capacity of this node for running jobs. This node has two executors, which means up to two jobs can be executed on this Jenkins instance at a time. If three jobs are started, then the first two started will execute and the third one will be added to the Build Queue, as shown in this screenshot
In this example, the jobs
Josh-JS-Karma jobs were started first and were assigned an executor, and the
Josh-AddressBook-TestNG job has been queued and is waiting for an executor assignment. Once an executor is available after a job has finished, the third job will be assigned to it and run.
Adding multiple nodes on Jenkins is straightforward. This allows multiple nodes to be used for multiple OSs/platforms, load balancing jobs, and other functions. When you add a label to a node, you can restrict the running of specific jobs on that node.
If you want to add a label to an existing node, navigate to Manage Jenkins > Manage Nodes > <Select Node> > Configure, and add the label to the node. You can add labels to as many nodes as you want to use as resources for specific jobs.
Once you have configured your jobs to run on specific nodes, they will queue to run on that node based on the number of available executors, as described in the example.