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

Cur*_*ire 3 jenkins jenkins-plugins jenkins-groovy jenkins-pipeline

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

node()
{
   sh 'git log ...'
}
Run Code Online (Sandbox Code Playgroud)

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

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

谢谢您的帮助!

Sud*_*ran 5

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

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()
Run Code Online (Sandbox Code Playgroud)