简体   繁体   中英

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!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM