I'm trying to set the number of executors in Jenkins using Groovy. I've found a method hudson.model.Hudson.instance.setNumExecutors(int) but it doesn't seem to really work. The problem is that the modified value appears in the configuration panel after I run the Groovy script, but I have to click 'Save' in that panel to really have it changed.
Here's the code (executed as a build step with Jenkins Groovy plugin):
import hudson.model.*
// Initial number of executors is 1, let's increase the number of executors to 2
Hudson hudson = Hudson.getInstance()
hudson.setNumExecutors(2)
hudson.save()
def job = hudson.getJob("some_other_job")
def future = job.scheduleBuild2(0, new Cause.UpstreamCause(build))
subBuild = future.get()
// Set the number of executors back to 1
hudson.setNumExecutors(1)
hudson.save()
The solution is to call hudson.setNodes(hudson.getNodes())
after calling setNumExecutors()
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With