Jenkins command to get number of builds in queue

匿名 (未验证) 提交于 2019-12-03 02:24:01

问题:

I am trying to get the number of builds in the Jenkins Build Queue.

May I know the Jenkins command to get the number of builds running in the queue ?

回答1:

See Jenkins' Remote access API.

Access the API description with:

  http://<Your Jenkins>/api/ 

and the actual data with:

  http://<Your Jenkins>/api/xml 

The Build queue has its own separate API:

  http://<Your Jenkins>/queue/api/ 

with its data:

  http://<Your Jenkins>/queue/api/xml 


回答2:

That's easy to do with Jenkins Script Console:

println Hudson.instance.queue.items.length // => 2 

Also that's possible to execute groovy script remotely. For example, from command line:

$ curl -u username:password -d "script=println Hudson.instance.queue.items.length" jenkins_url/scriptText 2 

Note: user with specified username should have access to Jenkins Script Console.



回答3:

Here is a shell script implementation of the mentioned Jenkins REST API

_queuesize=$(curl -s -k -m 60 http://${yourjenkinsserver}:8180/jenkins/queue/api/xml 2>/dev/null | grep -c '<item>') if [[ -z "${_queuesize}" ]]; then   _queuesize=0; fi 


回答4:

Try Jenkins API in Python.

get_jobs()   Get list of jobs running.   Each job is a dictionary with ‘name’, ‘url’, and ‘color’ keys. Returns:    list of jobs, [ { str: str} ] 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!