I have this unique requirement to check if the given node is running a job or not. I am thinking of using groovy as it looks easiest option.
I have found this answer
Let me propose a very simple and efficient way
Each node stores the information related to if it example : idle or not , offline or not etc
You can get those details using below command
curl -X GET --silent -u jenkins_user:${jenkins_pwd} "http://your_jenkins_url:8080/computer/node_name/api/json"
or directly from browser
http://your_jenkins_url:8080/computer/node_name/api/jso
This result provides valuable information related to slave.
If you want narrow down the search to a specific thing like , is the slave idle or not then you can append it with below logic
curl -X GET --silent -u jenkins_user:${jenkins_pwd} "http://jenkins_domanin:8080/computer/node_name/api/json" | python -c 'import json,sys,os;obj=json.load(sys.stdin);print obj["idle"]'