How to find jenkins node ip address from wizard

Starting from the node master script console or from the groovy script system (which is also executed on the host computer), how can I get the IP address (s) of the slave node?

+1
source share
2 answers

I was hoping this simple script would be enough:

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, this does not give me the result that I want on systems with multiple network interfaces.

You can use the “run the command on the slave” technique from the answer to “How to execute the system command on the remote node” to run something like /sbin/ifconfig on each slave device. This will certainly give you the details, but I don't have Groovy savvy to write an output parser for extracting IP addresses.

+5
source

@ Dive Baher's answer will give you all the IP for this host. Assuming your subordinate SSHs are based, this will give you the strictly IP that the agent uses:

 def jenkins = jenkins.model.Jenkins.instance for (node in jenkins.nodes) { println "${node.nodeName}: node.toComputer().launcher.host" } 
+2
source

All Articles