I have a job in Jenkins. A website of our own triggers builds of this job via the REST api. Sometimes we want to abort the build. Sometimes, it can be before the build is even started. In such cases we have the queueItem # instead of the build #.
How to do so via the REST api ?
The jenkins-rest library is an object oriented Java project that provides access to the Jenkins REST API programmatically to some remote API Jenkins provides. It is built using the jclouds toolkit and can easily be extended to support more REST endpoints.
If the build has started, by POST
on:
http://<Jenkins_URL>/job/<Job_Name>/<Build_Number>/stop
Will stop/cancel the current build.
If the build has not started, you have the queueItem
, then POST
on:
http://<Jenkins_URL>/queue/cancelItem?id=<queueItem>
This is assuming your Jenkins Server has not been secured, otherwise you need to add BASIC authentication for a user with Cancel privileges.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With