[英]How to execute shell from Active Choices Plugin groovy script in Jenkins
I am trying to render information obtained from the shell in an active Active Choices parameter with a groovy script. 我正在尝试使用groovy脚本在活动的Active Choices参数中呈现从外壳获得的信息。 I can easily access the shell from a groovy script in a jenkins pipeline with the sh method like this:
我可以使用sh方法从jenkins管道中的groovy脚本轻松访问shell:
node()
{
sh 'git log ...'
}
But when I try this in the groovy script of Active choices, it crashes and the fallback script is executed. 但是,当我在Active选项的常规脚本中尝试此操作时,它将崩溃并执行后备脚本。
Is it possible to switch to a node in this context and execute a shell command ? 是否可以在这种情况下切换到节点并执行shell命令?
Thanks for the help! 谢谢您的帮助!
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()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.