尝试使用选项列表填充Jenkins参数但参数保持为空,可能是什么原因?

时间:2017-11-09 16:47:11

标签: jenkins groovy dropdownchoice

我正在使用Jenkins“Extensible Choice”插件,以便使用AWS RDS数据库实例名称列表填充参数。

在“Choice provider”中,我选择了“System groovy choice parameter”。

这是一个groovy代码,它应该返回DB的列表:

//Create buffer to capture command's Standard Out
def sout = new StringBuffer(), serr = new StringBuffer()

//Define here the shell command you would like to execute
def proc = 'aws rds describe-db-instances | grep DBInstanceIdentifier | grep -v Read | awk "{print \$2}" | sed "s/\"//g"'.execute()

//Capture command output into buffer
proc.consumeProcessOutput(sout, serr)

//Time to wait for command to complete
proc.waitForOrKill(1000)

//Converts command output to a list of choices, split by whitespace
return sout.tokenize()

如果我在shell中运行命令,我会正确获得输出:

[ec2-user@jenkins.company.com ~]$ aws rds describe-db-instances | grep DBInstanceIdentifier | grep -v Read | awk "{print \$2}" | sed "s/\"//g"
company
company-dev-70-mysql
dev-rds-2017-10-02
company-check-woocommerce
prod

但是当我运行这份工作时,下拉菜单会保持空白状态。

知道我做错了吗?

1 个答案:

答案 0 :(得分:0)

第二个是 StringBuilder 而不是缓冲区。

def sout = new StringBuffer(),serr = new StringBuilder()