简体   繁体   English

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

[英]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.

相关问题 Jenkins:从Active Choices参数groovy脚本访问其他插件 - Jenkins: Accessing other plugins from Active Choices Parameter groovy script 如何使用 Jenkins 主动选择参数 groovy 脚本在远程服务器中执行 shell 脚本? - How to execute shell script in remote server using Jenkins Active choice parameter groovy script? Jenkins 声明式管道:如何从“主动选择反应引用参数的 Groovy 脚本”调用函数? - Jenkins Declarative Pipeline: How to call functions from "Active choices reactive reference parameter's Groovy script"? 如何在 Jenkins 的活动选择参数中将简单的 shell 命令作为常规脚本执行? - How do I execute a simple shell-command as a groovy script in the active choice parameter in Jenkins? Jenkins Active选择参数,如何使用groovy执行aws shell命令 - Jenkins Active choice parameter, how to execute aws shell command with groovy 如何在詹金斯的另一个活动选择参数的groovy脚本中读取活动选择参数的值? - how read active choices parameter value in another active chocices parameter's groovy script in jenkins? 如何在参数选项中从Jenkins groovy脚本执行shell脚本? - How do I execute shell script from Jenkins groovy script in the parameters option? Jenkins - 主动选择插件 - Jenkins - Active Choices Plugin Jenkins Groovy 脚本来执行 shell 命令 - Jenkins Groovy script to execute shell commands 如何在Jenkins中执行Shell脚本 - How to execute a shell script in Jenkins
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM