Finding IP of a Jenkins node

The most efficient and platform-independent way to find out the IP is probably the following groovy code for the "global" Script Console on the master:

import hudson.model.Computer.ListPossibleNames

def node = jenkins.model.Jenkins.instance.getNode( "myslave" )
println node.computer.getChannel().call(new ListPossibleNames())

In the console, this yields (for example)

Result
[192.168.0.17]

The result is a list of strings, as there's potentially multiple IP addresses on one machine.

Since this does not require the node-specific consoles, it's easy to add a loop around the code that covers all nodes.


Through the Script Console (Manage Jenkins -> Nodes -> Select a node -> Script Console) of the node we can execute groovy script. Run the following command to get the IP address.

println InetAddress.localHost.canonicalHostName

Tags:

Jenkins