5

how to cancel build queue jobs in jenkins through REST API, which are not started by jenkins and are in its build queue. I know how to cancel the in-progress job with below command

curl -X POST <jenkins-server>/job/<job-name>/<build-number>/doDelete                        
StephenKing
  • 36,187
  • 11
  • 83
  • 112

2 Answers2

6

To cancel a job in the queue, you can POST:

http://jenkins/queue/cancelItem?id=x

To find x, you can parse the result of:

http://jenkins/queue/api/json?tree=items[id,task[name]]

To cancel a build that is in progress:

http://jenkins/job/<jobName>/y/stop

To find y, you can parse the result of:

http://jenkins/job/<jobName>/lastBuild/api/json?tree=building,number
Allan
  • 107
  • 4
  • thanks allan, but as I am automating this from front-end its becoming quite difficult to delete or cancel particular job with only ID. Can we stop jenkins from making build queue ? – tusharkumar singhal Dec 15 '15 at 13:50
1

It's not possible to cancel a job by its build number, only through the job id:

curl -X POST 'http://jenkins/queue/cancelItem?id=85'
Eduardo Yáñez Parareda
  • 9,126
  • 4
  • 37
  • 50