how to cancel build queue jobs in jenkins, which are not started by jenkins and are in its build queue through REST API
10,297
Solution 1
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
Solution 2
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'
Author by
tusharkumar singhal
Updated on June 05, 2022Comments
-
tusharkumar singhal almost 2 years
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
-
tusharkumar singhal over 8 yearsNo its not working, i tried curl -X POST http://<jenkins-server>/queue/cancelItem?id=152 , curl --data '' http://<jenkins-server/queue/cancelItem?id=154 and whenever i am posting this link http://<jenkins-server/queue/cancelItem?id=154 output is -POST is required for hudson.model.Queue.doCancelItem, so can't we do something with doCancelItem which I did similarly with doDelete?
-
Eduardo Yáñez Parareda over 8 yearsWell, --data '' is used for sending a POST request with curl.
-
Eduardo Yáñez Parareda over 8 yearsTry curl --request POST 'jenkins/queue/cancelItem?id=154' or curl -X POST '.....id=154'
-
tusharkumar singhal over 8 yearsNo its not working, curl --request POST <jenkins>/queue/cancelItem?id=167
-
tusharkumar singhal over 8 yearsHi Eduardo, sorry this one worked but only with id, I am trying to do this with build number
-
Eduardo Yáñez Parareda over 8 yearstry with build=XXX instead of id=XXX
-
tusharkumar singhal over 8 yearsalso i think it will be more feasible to find a way to do cancelitem like this - : curl -X POST <jenkins-server>/job/<job-name/164/doDelete...as I am automating this from a website, cause particular job name and its build number becomes systematic
-
tusharkumar singhal over 8 yearsBoth are not working..it seems jenkins only taking id, curl --request POST <jenkins>/queue/cancelItem?build=167 or curl --request POST <jenkins>/queue/cancelItem?nextBuildNumber=167
-
tusharkumar singhal over 8 yearsthanks 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 ?