3
votes

I am trying to render information obtained from the shell in an active Active Choices parameter with a groovy script. I can easily access the shell from a groovy script in a jenkins pipeline with the sh method like this:

node()
{
   sh 'git log ...'
}

But when I try this in the groovy script of Active choices, it crashes and the fallback script is executed.

Is it possible to switch to a node in this context and execute a shell command ?

Thanks for the help!

1

1 Answers

5
votes

Here is sample snippet using the active choice plugin.

def command = $/aws ec2 describe-instances \
               --filters Name=tag:Name,Values=Test \
               --query Reservations[*].Instances[*].PrivateIpAddress \
               --output text /$
def proc = command.execute()
proc.waitFor()              

def output = proc.in.text
def exitcode= proc.exitValue()
def error = proc.err.text

if (error) {
    println "Std Err: ${error}"
    println "Process exit code: ${exitcode}"
    return exitcode
}

//println output.split()
return output.tokenize()