通过 Masters 的脚本控制台在所有 Jenkins slave 上运行远程命令 [英] Run a remote command on all Jenkins slaves via Masters's script console
本文介绍了通过 Masters 的脚本控制台在所有 Jenkins slave 上运行远程命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在所有 UNIX 从站上运行相同的 shell 命令(非常简单的 shell 命令,如 ls
)使用 master 的脚本控制台连接到 master.
I want to run same shell command (very simple shell commands like ls
) on all the UNIX slaves
which are connected to the master by using the master's script console.
如何使用 groovy 执行此操作?
How can I do this using groovy?
想做这样的事情:显示关于节点的信息但不是显示信息,我还想在每个从站上运行一些简单的 UNIX 命令并打印结果.
Want to do something like this: Display Information About Nodes but instead of displaying information, I want to also run some simple UNIX commands on each slave and print the results.
推荐答案
import hudson.util.RemotingDiagnostics;
print_ip = 'println InetAddress.localHost.hostAddress';
print_hostname = 'println InetAddress.localHost.canonicalHostName';
// here it is - the shell command, uname as example
uname = 'def proc = "uname -a".execute(); proc.waitFor(); println proc.in.text';
for (slave in hudson.model.Hudson.instance.slaves) {
println slave.name;
println RemotingDiagnostics.executeGroovy(print_ip, slave.getChannel());
println RemotingDiagnostics.executeGroovy(print_hostname, slave.getChannel());
println RemotingDiagnostics.executeGroovy(uname, slave.getChannel());
}
这篇关于通过 Masters 的脚本控制台在所有 Jenkins slave 上运行远程命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文