Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop a build in Jenkins via the REST api ?

Tags:

rest

jenkins

api

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 ?

like image 966
Barth Avatar asked Jan 09 '14 13:01

Barth


People also ask

Does Jenkins have a 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.


1 Answers

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.

like image 55
Jifeng Zhang Avatar answered Sep 21 '22 13:09

Jifeng Zhang