Jenkins How to find if a given slave is running a Job

前端 未结 3 856
盖世英雄少女心
盖世英雄少女心 2021-01-05 08:21

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

3条回答
  •  情深已故
    2021-01-05 09:04

    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"]'
    

提交回复
热议问题