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

问题描述 投票:0回答:1

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

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

但是当我在Active选项的groovy脚本中尝试这个时,它会崩溃并执行回退脚本。

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

谢谢您的帮助!

jenkins jenkins-plugins jenkins-pipeline jenkins-groovy
1个回答
2
投票

以下是使用有效选择插件的示例代码段。

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()
© www.soinside.com 2019 - 2024. All rights reserved.