Reputation: 6305
I'm using Jenkins "Extensible Choice" plugin in order to populate a parameter with a list of AWS RDS DB instance names.
In "Choice provider" I chose "System groovy choice parameter".
This is the groovy code which is supposed to return the list of DB's:
//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()
If I run the command in a shell, I get the output properly:
[[email protected] ~]$ 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
But when I run the job, the drop down menu stays empty.
Any idea what I'm doing wrong?
Upvotes: 4
Views: 1792
Reputation: 3256
The second is StringBuilder not Buffer.
def sout = new StringBuffer(), serr = new StringBuilder()
Upvotes: 0