How to find the ip address of a jenkins node from the master

后端 未结 2 459
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-15 09:11

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?

2条回答
  •  春和景丽
    2021-01-15 09:30

    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.

    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.

提交回复
热议问题