4

I want to know the whether the build executors in jenkins are idle(either free or any job is running in the master node), by using java-jenkins API. And my requirement is like this.

  1. If any executor is free I've to trigger a jenkins job otherwise I'll wait till they are available.
  2. For this I've to use API of Jenkins
  3. And all this implementation I've to do in Java

Please help me which API method will give that status of executor.Executors are the highlighted things shown in the pic below:

Biruk Abebe
  • 2,235
  • 1
  • 13
  • 24
3lokesh
  • 53
  • 1
  • 1
  • 4

2 Answers2

7

System groovy script to check if slaves are online and idle.

import hudson.model.Node
import hudson.model.Slave
import jenkins.model.Jenkins

Jenkins jenkins = Jenkins.instance
def jenkinsNodes =jenkins.nodes

for (Node node in jenkinsNodes) 
{
    // Make sure slave is online
    if (!node.getComputer().isOffline()) 
    {           
        //Make sure that the slave busy executor number is 0.
        if(node.getComputer().countBusy()==0)
        {
           ...Do somthing...
        }
    }
}
Dvir669
  • 6,577
  • 1
  • 20
  • 21
0

maybe you can use jenkins inner api: like http://10.199.162.87:8080/computer/10.199.168.126/ajaxExecutors

enter image description here

the jenkins response is

<div id="executors" class="container-fluid pane-frame track-mouse expanded"><div class="row"><div class="col-xs-24 pane-header"><a href="/toggleCollapse?paneId=executors" title="collapse" class="collapse"><img src="/static/0aae4c16/images/16x16/collapse.png" alt="collapse" style="width: 16px; height: 16px; " class="icon-collapse icon-sm" /></a><a href='/computer/'>Build Executor Status</a></div></div><div class="row pane-content"><table class="pane "><colgroup><col width="30" /><col width="200*" /><col width="24" /></colgroup><tr></tr><tr><td class="pane" align="right" style="vertical-align: top">1</td><td class="pane">Idle</td><td class="pane"></td><td class="pane"></td></tr><tr><td class="pane" align="right" style="vertical-align: top">2</td><td class="pane">Idle</td><td class="pane"></td><td class="pane"></td></tr></table></div></div>

it contains "Idle"