How can check if the hudson is busy or not? Meaning i want to check if its currently executing any build or not.
Currently am using following thing:
if(lastBuild == lastCompletedBuild){
// hudson is free
}
else{
//hudson is busy
}
Is this a correct logic? What if the machine restarts/crashes after last build is updated and lastCompletedbuild is not?
Is there any API exposed which can directly be used?
If you want to see what items are currently in the build queue, you can make an request to http://your.hudson.server/hudson/queue/api/[xml|json]
.
Look at Hudson's API.
Specifically: You can add /api/[xml|json]
to any path in Hudson to get machine readable data of that page. For example hudsonserver:8080/api/xml
will return the list of job and their current statuses.
However, the real question i where is this code being executed? Above, you have lastBuild
and lastCompletedBuild
, but where did those variables get set?
You can try to query the Load Statistics available at a separate API:
<overallLoadStatistics>
<busyExecutors></busyExecutors>
<queueLength></queueLength>
<totalExecutors></totalExecutors>
<totalQueueLength></totalQueueLength>
</overallLoadStatistics>
Are you interested in whether a specific job is currently building? In that case:
http://[hudson-host-and-path]/job/[job-name]/lastBuild/api/xml
has the tag <building>
set to true if a build is currently happening.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With