aRTURIUS
aRTURIUS

Reputation: 1370

Groovy script set number of executors

Please help me, I'm trying to change the number of executors on jenkins. When I'm running this code, it works:

import jenkins.model.Jenkins
Jenkins jenkins = Jenkins.getInstance()
jenkins.setNumExecutors(4)
jenkins.save()

When I use the next function:

void set_executors(int number) {

Jenkins jenkins = Jenkins.getInstance()
jenkins.setNumExecutors(number)
jenkins.save()
}

And running:

java -jar jenkins-cli.jar -s http://localhost:8080 groovy /var/lib/jenkins/executor.groovy set_executors 4

I'm getting:

groovy.lang.MissingMethodException: No signature of method:
Actions.set_executors() is applicable for argument types
(java.lang.String) values: [4]
Possible solutions: set_executors(int)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:55)

Please help!

Upvotes: 0

Views: 1684

Answers (1)

Dave Bacher
Dave Bacher

Reputation: 15972

When run from the command line, groovy passes arguments as strings. Your set_executors function is being called with a String argument instead of an integer as the function expects. You need to modify your code to accept a String argument and convert it to an integer.

Upvotes: 2

Related Questions