Jenkins command to get number of builds in queue Jenkins command to get number of builds in queue jenkins jenkins

Jenkins command to get number of builds in queue


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


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/scriptText2

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


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