I have the following Groovy script, called by a Jenkins pipeline job:
import jenkins.model.Jenkins
def foo(){
Jenkins.instance.getNode('bla').getComputer.disconnect()
}
Checking thegetComputer()
API , I wasn't able to find a way to also get the IP of the node. Is it possible from within the jenkinsfile / groovy script?
This what worked for me eventually. The trick is to run it from master (so the desired node won't be recognized as "local host"
def find_ip(node_name){
for (slave in Jenkins.instance.slaves) {
host = slave.computer.hostName
addr = InetAddress.getAllByName(host)
if (! slave.name.trim().equals(node_name.trim())) { continue }
return host
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.