Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-69291

How to extract parameters of Build in Build Queue

    • Icon: Bug Bug
    • Resolution: Not A Defect
    • Icon: Minor Minor
    • jenkinsfile-runner
    • None
    • jenkins 1.652

      hello,

      More than 10000 Builds are stacked in the Build Queue.
      So, I want to back up information about this build and delete the build queue that is currently accumulated.
      Is there a way to get parameter values of Builds in Build Queue and back them up?
      Also, how can I delete the Build Queue at once?

      thank you

          [JENKINS-69291] How to extract parameters of Build in Build Queue

          Ian Williams added a comment - - edited

          This Issue Tracker is to report Jenkins issues, not seek support. Support questions should go to StackOverlflow, Community, or Gitter.

          Nevertheless, these groovy bits  will get you started. To list all jobs in the queue, if parameterized and why in the queue.

          // Get Job Queue details:
          jenkins.model.Jenkins.instance.queue.items.each {job ->
            println 'JOB: ' + job.task.getFullName() + " : " + job.task.isParameterized()
            println '     ' + job.getInQueueForString() + " : " +  job.getWhy()  + " : " + job.getCausesDescription().trim()
            
            def parameters = job.getAllActions().find{ it instanceof ParametersAction }?.parameters
            parameters.each {
               def dump = it.dump()
               println "  P: ${it.name}: ${dump}"
             }
          
          }
          return

          Clearing the queue:

          // Clear the entire Job Queue:
          Jenkins.instance.queue.clear()
          // Clear select jobs
          def pattern = 'my_text'
          def q = Jenkins.instance.queue
          
          q.items.findAll { it.task.name.contains($pattern) }.each { job ->
             println job.task.name
             q.cancel(job.task)
          } return

           Closing out ticket.

          Ian Williams added a comment - - edited This Issue Tracker is to report Jenkins issues, not seek support. Support questions should go to StackOverlflow , Community , or Gitter . Nevertheless, these groovy bits  will get you started. To list all jobs in the queue, if parameterized and why in the queue. // Get Job Queue details: jenkins.model.Jenkins.instance.queue.items.each {job ->   println 'JOB: ' + job.task.getFullName() + " : " + job.task.isParameterized()   println '     ' + job.getInQueueForString() + " : " +  job.getWhy()  + " : " + job.getCausesDescription().trim()      def parameters = job.getAllActions().find{ it instanceof ParametersAction }?.parameters   parameters.each {      def dump = it.dump()      println "  P: ${it.name}: ${dump}"    } } return Clearing the queue: // Clear the entire Job Queue: Jenkins.instance.queue.clear() // Clear select jobs def pattern = 'my_text' def q = Jenkins.instance.queue q.items.findAll { it.task.name.contains($pattern) }.each { job -> println job.task.name q.cancel(job.task) } return  Closing out ticket.

            Unassigned Unassigned
            lww4152 Lee Wonwoo
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: