Skip to main content
Version: QB13

Reduce Server Load

Scenario

In a continuous integration environment, it is important that builds can run as frequently as possible. A server could be configured with dozens of projects, with each project having several branches, with each branch having dozens of developers committing their code and requesting verification builds. This could impose a heavy load on the build server if all builds are executed on the single machine.

Solution

You can delegate build jobs from server to agents by running build steps only on the agent nodes. Let's take a typical build process for example, it has four steps, checkout , build , publish , and a default step to execute the other steps sequentially. By default, all three steps have property node match condition being set to following value:

current.parent==null?node.isServer():(node==current.parent.node)

This means that if the step does not have parent (in the case of the master step), it should be run on the server node; otherwise, it should be running on the same node as its parent node. The effect is that all steps are by default executed on the server node. To make all steps running on the agent nodes, just set the node match condition of the master step to be:

node.isAgent()

Other steps remain unchanged. When build starts, the master step will try to look for a compatible node available for execution. In this case, all agents are compatible, and one of the agents will be selected based on a load balancing algorithm. All other steps will use the same agent as the node match condition tells them to use the same node as their parent step.

In a real environment, it is possible that not all agent nodes are compatible with the build, and you can adjust the node match condition of the master step to filter off incompatible nodes. For example by using the expression node.isAgent() && (node.getAttribute("os.name").startsWith("Linux") || node.getAttribute("os.name").startsWith("LINUX")), which only accepts Linux agents.