69
votes

A windows slave node connected to Jenkins server through "Java web start". The system information of the node doesn't have it's IP address.

I had to run through all the slaves node we had, and find which machine (ip address) corresponds to the slave node in Jenkins.

Is there a way to find the IP address of a slave node from Jenkins itself?

8

8 Answers

73
votes

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
26
votes

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.

18
votes

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
11
votes

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

7
votes

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

1
votes

To get the ip on a Windows slave:

Navigate to the Script Console (Manage Jenkins -> Nodes -> Select a node -> Script Console)

println "ipconfig".execute().text
0
votes

In your Jenkins job if its in groovy or else echo the ifonfig sh "/sbin/ifconfig -a | grep inet"

-1
votes

Can also be found through the Jenkins UI: Manage Jenkins --> Manage Nodes --> Click Node name --> Configure

This should display both the public and private ip address of that node