首页 文章

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

提问于
浏览
2

我正在使用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

    第二个是 StringBuilder 而不是Buffer .

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

相关问题