Setting Jenkins Node Monitor Thresholds with Groovy

Mar 24, 2017

Today I ran across a case where we were trying to programmatically set the threshold for when Jenkins will automatically turn off a Jenkins agent (found under https://$YOUR_JENKINS_HOST/computer/configure). The default is 1GB and we’d like to bump that up a bit. We’re periodically wiping out any nodes that are offline (as well as the resources behind that node) so doing this will clean them out sooner.

Discovering how to do this turned out to be a bit trickier than normal. After some research I discovered that the DescribableList that comes from ComputerSet.getMonitors() was the ticket. DiskSpaceMonitor is obviously an idempotent object based on the doc so it seemed that replacing it somewhere was what was necessary. So, if you would like to replace any of the NodeMonitors in the hudson.node_monitors package (listed under https://$YOUR_JENKINS_HOST/computer/configure) then you can do something similar to this:

import hudson.node_monitors.DiskSpaceMonitor
ComputerSet.getMonitors().replace(new DiskSpaceMonitor("5GB"))


comments powered by Disqus