how to cancel build queue jobs in jenkins, which are not started by jenkins and are in its build queue through REST API
Asked Answered
E

2

6

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                        
Equilibrate answered 14/12, 2015 at 7:8 Comment(0)
B
7

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
Bloomfield answered 15/12, 2015 at 4:33 Comment(1)
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 ?Equilibrate
M
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'
Metasomatism answered 14/12, 2015 at 7:17 Comment(8)
No 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?Equilibrate
Well, --data '' is used for sending a POST request with curl.Heteropolar
Try curl --request POST 'jenkins/queue/cancelItem?id=154' or curl -X POST '.....id=154'Heteropolar
No its not working, curl --request POST <jenkins>/queue/cancelItem?id=167Equilibrate
Hi Eduardo, sorry this one worked but only with id, I am trying to do this with build numberEquilibrate
try with build=XXX instead of id=XXXHeteropolar
also 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 systematicEquilibrate
Both 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=167Equilibrate

© 2022 - 2024 — McMap. All rights reserved.