如何在 Jenkins 中从 Active Choices Plugin groovy 脚本执行 shell

How to execute shell from Active Choices Plugin groovy script in Jenkins

我正在尝试使用 groovy 脚本在活动的 Active Choices 参数中呈现从 shell 获得的信息。我可以使用这样的 sh 方法从 jenkins 管道中的 groovy 脚本轻松访问 shell:

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

但是当我在 Active choices 的 groovy 脚本中尝试此操作时,它崩溃并执行回退脚本。

是否可以切换到此上下文中的节点并执行 shell 命令?

感谢您的帮助!

这是使用主动选择插件的示例片段。

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()