Setting the number of artists in Jenkins using Groovy

I am trying to set the number of artists in Jenkins using Groovy. I found the hudson.model.Hudson.instance.setNumExecutors (int) method, but it doesn’t really work. The problem is that the changed value appears in the configuration panel after running the Groovy script, but I have to click “Save” in this panel to really change it.

Here's the code (done as a build step with the Jenkins Groovy plugin):

import hudson.model.*

// Initial number of executors is 1, let 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()
+3
source share
2 answers

The solution is to call hudson.setNodes(hudson.getNodes())after the call setNumExecutors().

+5
source

, , , , , , save Jenkins .

0

All Articles