在jenkins-cli groovy脚本中解析命令行

时间:2016-03-03 17:07:18

标签: jenkins groovy jenkins-cli

我编写了一个groovy脚本来从我的Jenkins服务器收集一些统计信息,在默认情况下可以正常工作。 但是,当我想传递选项时,我遇到了麻烦:

(1)标准groovy CliBuilder存在,但无法在jenkins-cli下实例化:

import jenkins.model.*
import groovy.util.CliBuilder
println("CliBuilder imported; calling constructor...")
def cli = new CliBuilder(usage: 'myscript.groovy [-halr] [name]')

结果

$ java -jar "jenkins-cli.jar" -s https://myjenkins1/ groovy myscript.groovy
CliBuilder imported; calling constructor...

ERROR: Unexpected exception occurred while performing groovy command.
java.lang.NoClassDefFoundError: org/apache/commons/cli/ParseException
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:195)
    at RemoteClass.class$(RemoteClass)
    at RemoteClass.$get$$class$groovy$util$CliBuilder(RemoteClass)
    at RemoteClass.run(RemoteClass:4)
    at groovy.lang.GroovyShell.runScriptOrMainOrTestOrRunnable(GroovyShell.java:266)
....

(2)以破折号开头的选项被jenkins-cli拦截,而不是将其传递给脚本

$ java -jar "jenkins-cli.jar" -s https://myjenkins/ groovy ./myscript.groovy -h
ERROR: "-h" is not a valid option
java -jar jenkins-cli.jar groovy [SCRIPT] [ARGUMENTS ...] [--username VAL] [--password VAL] [--password-file VAL]
Executes the specified Groovy script.
 SCRIPT              : Script to be executed. File, URL or '=' to represent
                       stdin.
 ARGUMENTS           : Command line arguments to pass into script.
 --username VAL      : User name to authenticate yourself to Jenkins
 --password VAL      : Password for authentication. Note that passing a
                       password in arguments is insecure.
 --password-file VAL : File that contains the password

这是否意味着jenkins-cli groovy界面仅用于简单的任务,不应该处理复杂的命令行? 或者这些已知的警告是否具有已知的解决方法?

0 个答案:

没有答案