如何从主服务器查找詹金斯节点的IP地址 [英] How to find the ip address of a jenkins node from the master
问题描述
从主节点脚本控制台或系统groovy脚本(也在主服务器上运行)运行时,如何获取从属节点的ip地址?
Running from the master node scripting console, or from the a system groovy script (that also runs on the master), how do I get the ip address(es) of a slave node?
推荐答案
我希望这个简单的脚本就足够了:
I was hoping that this simple script would suffice:
import java.net.*
for (slave in Jenkins.instance.slaves) {
host = slave.computer.hostName
addr = InetAddress.getAllByName(host)
println slave.name + ": " + addr.hostAddress
}
但是至少在我的安装中,它没有给我想要的具有多个网络接口的系统的结果.
But at least with my installation, it does not give me the result I want on the systems that have multiple network interfaces.
您可以使用如何在远程节点上执行系统命令"的答案中的在从属服务器上运行命令"技术. 在每个从站上运行类似/sbin/ifconfig
的内容.当然可以为您提供详细信息,但是我没有Groovy的精通技巧来编写输出解析器以提取IP.
You could use the "run a command on the slave" technique from the answer to "How to execute system command on remote node" to run something like /sbin/ifconfig
on each slave. That would certainly give you the details, but I don't have the Groovy savvy to write up an output parser to extract the IPs.
这篇关于如何从主服务器查找詹金斯节点的IP地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!