문제

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 everything is working as you expect except you have to press the save button manually to make the changes stick then it sounds like you didn't call save on your Jenkins instance after you made your changes.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top