简体   繁体   English

Groovy脚本集执行者数

[英]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. 从命令行运行时,groovy将参数作为字符串传递。 Your set_executors function is being called with a String argument instead of an integer as the function expects. 您的set_executors函数使用String参数而不是函数期望的整数进行调用。 You need to modify your code to accept a String argument and convert it to an integer. 您需要修改代码以接受String参数并将其转换为整数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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