pythonapijenkinsjenkins-api

Is there a function in any Jenkins API that provides me with a slave nodes COMPUTERNAME/Hostname


I need to get together a list of all the hostnames of the jenkins slave nodes set up on my jenkins master node. Many of the nodes are set up with names like SLAVE NODE EXAMPLE instead of having their server name as the name of the node. I know how to get to this from the UI. However I need to access this through python as I have many nodes set up and it will be a long process to manually go through each one.

I am using the python-jenkins api which has a function that gets me all the nodes and their configurations. using get_node_config(name). However it does not provide me with the COMPUTERNAME. I can't seem to find the file that contains that information int the Jenkins Home directory either.


Solution

  • Here's a groovy script if that helps. Run from the console. Note: nodes must be on-line to query.

    Jenkins.instance.slaves.each {
       print it.getNodeName() + ' : '
       if ( it.getComputer().isOnline() ) {
          println it.getComputer().getHostName() + ' : ' + it.getComputer().getOSDescription()
       } else {
          println ' - offline -'
       }    
    }
    return 0
    

    See Jenkins API - Computer