4

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:

[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

But when I run the job, the drop down menu stays empty.

Any idea what I'm doing wrong?

Itai Ganot
  • 5,873
  • 18
  • 56
  • 99

1 Answers1

0

The second is StringBuilder not Buffer.

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

Joao Vitorino
  • 2,976
  • 3
  • 26
  • 55
  • Thanks, I've fixed it, but it still doesn't populate the menu with anything... any other ideas? – Itai Ganot Nov 09 '17 at 18:16
  • Yes, the jenkins user gets the proper output as shown in the question – Itai Ganot Nov 09 '17 at 19:42
  • In the question you use ec2-user, are you sure that jenkins are who run jenkins can execute the command? If yes, check jenkins log. – Joao Vitorino Nov 09 '17 at 19:47
  • That's true but anyways jenkins user is able to run the command as well and there's nothing in the log regarding this... like nothing... – Itai Ganot Nov 09 '17 at 21:57
  • 1
    You need to return either the list from the return or they should be separated by new line character (not white space). try that one. – Arun Jul 31 '18 at 06:35