2

Is there a possibility to request the list of Jenkins slave ips,
inside of a Jenkins freestyle job,
when executing a shell script?

Maybe as an environment variable?

Skip
  • 6,240
  • 11
  • 67
  • 117
  • This question is very similar to another question which was answered here: http://stackoverflow.com/a/31692758/4360457 – Bricktop Oct 17 '16 at 15:46
  • No it is not. There you can find an answer to the question "How to get an ip-address of a particular slave." So you have to know it's name. As stated in my question - i requested a LIST OF JENKINS SLAVE IPS. So ips of all slaves available or ips of slaves by label.. – Skip Oct 18 '16 at 07:57

1 Answers1

0

You can determine the IP address(es) of a slave node via groovy. See this answer.

So you could proceed as follows:

  1. Create a groovy build step that will write the IP addresses of all slaves of interest to a text file
  2. In you shell script build step, read IP addresses from that file.

As an example, this groovy code will print the names and IP addresses of all slaves with label mylabel:

import hudson.model.Computer.ListPossibleNames

slaves = Hudson.instance.slaves.findAll { it.getLabelString().split() contains 'mylabel' }
slaves.each {
  println "slave '${it.name}' has these IPs: " +  it.getChannel().call(new ListPossibleNames())
}

Sample output:

slave 'foo' has these IPs: [10.162.0.135]
Community
  • 1
  • 1
Alex O
  • 7,746
  • 2
  • 25
  • 38
  • And to get the names of all nodes one can use the JSON API. Assume Jenkins is running on localhost:8080 it would be localhost:8080/computer/api/json – Skip Oct 18 '16 at 08:47
  • I'd rather do that on groovy level also, so you have all the selection and reporting stuff in one clean step. I'll extend the anser accordingly. – Alex O Oct 18 '16 at 09:25