Finding IP of a Jenkins node

Solution 1:

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

Solution 2:

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.

Solution 3:

To answer this same question on a non-windows Jenkins slave:

Get the IP address:

println "ifconfig".execute().text

Get the hostname:

println "hostname".execute().text

Solution 4:

From the Web Interface

Go to the node's Log link:

http://jenkins.mycompany.com:8080/computer/my_node_name/log

The first line should say something like:

JNLP agent connected from /10.11.12.123

screenshot

screenshot

Solution 5:

This is very similar to what deepak explained but I added images along the short steps.

In Jenkins UI click:

Manage Jenkins -> Nodes -> Select a node -> Script Console

then run println InetAddress.localHost.canonicalHostName

enter image description here