Finding IP of a Jenkins node

Jenkins

Jenkins Problem Overview


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?

Jenkins Solutions


Solution 1 - Jenkins

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 - Jenkins

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 - Jenkins

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 - Jenkins

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 - Jenkins

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

Solution 6 - Jenkins

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

Solution 7 - Jenkins

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

Solution 8 - Jenkins

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestiondeepakView Question on Stackoverflow
Solution 1 - JenkinsdeepakView Answer on Stackoverflow
Solution 2 - JenkinsAlex OView Answer on Stackoverflow
Solution 3 - JenkinsAdam KalnasView Answer on Stackoverflow
Solution 4 - JenkinsSridhar SarnobatView Answer on Stackoverflow
Solution 5 - JenkinsgrepitView Answer on Stackoverflow
Solution 6 - JenkinsbenathonView Answer on Stackoverflow
Solution 7 - JenkinssubbuView Answer on Stackoverflow
Solution 8 - JenkinsSCoyleView Answer on Stackoverflow