Daniel Sperry
Daniel Sperry

Reputation: 4491

How to find the ip address of a jenkins node from the master

Running from the master node scripting console, or from the a system groovy script (that also runs on the master), how do I get the ip address(es) of a slave node?

Upvotes: 2

Views: 11931

Answers (2)

James
James

Reputation: 1410

@Dave Bacher's answer will give you all IP's for the given host. Assuming your slaves are SSH based, this will give you strictly the IP that the agent uses:

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

Upvotes: 4

Dave Bacher
Dave Bacher

Reputation: 15972

I was hoping that this simple script would suffice:

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

You could use the "run a command on the slave" technique from the answer to "How to execute system command on remote node" to run something like /sbin/ifconfig on each slave. That would certainly give you the details, but I don't have the Groovy savvy to write up an output parser to extract the IPs.

Upvotes: 5

Related Questions