通过Masters的脚本控制台在所有Jenkins从站上运行远程命令 [英] Run a remote command on all Jenkins slaves via Masters's script console

查看:351
本文介绍了通过Masters的脚本控制台在所有Jenkins从站上运行远程命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在所有的UNIX主从
上运行相同的shell命令(非常简单的shell命令,例如 ls ),脚本控制台。



我如何使用groovy来做到这一点?



想做这样的事情:显示关于节点的信息
但我并不想显示信息在每个slave上运行一些简单的UNIX命令并打印结果。

解决方案

  import hudson。 util.RemotingDiagnostics; 

print_ip ='println InetAddress.localHost.hostAddress';
print_hostname ='println InetAddress.localHost.canonicalHostName';

//这里是 - shell命令,uname作为例子
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());
}


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.

How can I do this using groovy?

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从站上运行远程命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆