Finding IP of a Jenkins node

前端 未结 8 1359
慢半拍i
慢半拍i 2020-12-23 15:52

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

相关标签:
8条回答
  • 2020-12-23 16:21

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

    0 讨论(0)
  • 2020-12-23 16:25

    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.

    0 讨论(0)
  • 2020-12-23 16:28

    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

    0 讨论(0)
  • 2020-12-23 16:29

    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

    0 讨论(0)
  • 2020-12-23 16:40

    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
    
    0 讨论(0)
  • 2020-12-23 16:40

    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
    
    0 讨论(0)
提交回复
热议问题