通过Masters的脚本控制台在所有Jenkins从站上运行远程命令

cof*_*Mug 9 groovy jenkins

我想在ls使用master的脚本控制台连接到master的所有UNIX从服务器上运行相同的shell命令(非常简单的shell命令).

我怎么能用groovy做到这一点?

想要做这样的事情:显示有关节点 的信息,但我想在每个从站上运行一些简单的UNIX命令并打印结果,而不是显示信息.

Iva*_*ass 16

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