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.
If any executor is free I've to trigger a jenkins job otherwise I'll wait till they are available.
For this I've to use API of Jenkins
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:
解决方案
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...
}
}
}