Jenkins command to get number of builds in queue

前端 未结 5 976
傲寒
傲寒 2021-01-04 00:54

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 ?

相关标签:
5条回答
  • 2021-01-04 01:30

    This single bash variable definition using the awesome "jq" utility was all I needed to get the queue length:

      QUEUE_SIZE=$(curl -s -k http://<your-jenkins-here>/queue/api/json | jq '.items | length')
    

    Hope this helps.

    0 讨论(0)
  • 2021-01-04 01:34

    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
    
    0 讨论(0)
  • 2021-01-04 01:40

    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.

    0 讨论(0)
  • 2021-01-04 01:46

    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
    
    0 讨论(0)
  • 2021-01-04 01:54

    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} ]
    
    0 讨论(0)
提交回复
热议问题