HUDSON: How to stop hudson job from command line?
Asked Answered
A

2

8

I need to forcefully stop a Hudson build running in remote server. Is there a command/API to do that?

for ex: to trigger a new build we can do :- HUDSON_URL/job/JOBNAME/build

looking for similar API to stop the build.

Amerind answered 25/4, 2011 at 10:38 Comment(0)
R
10

You should be able to make a http request to

http://HUDSON_URL/job/JOBNAME/BUILDNUMBER/stop

and you can do a xpath request to get the build number

http://HUDSON_URL/job/JOBNAME/api/xml?xpath=//lastBuild/number/text()

There may be a way to put in latestBuild or lastBuild instead of BUILDNUMBER, but if not, you can just use 2 http gets.

Ramburt answered 25/4, 2011 at 20:54 Comment(0)
P
3

From the above answer (upvoted), @girishs' comment, and some work of my own, in a Windows environment (Linux could probably use wget instead of curl, haven't tested):

curl --request POST -u <USER>:<PASS> "%JENKINS_URL%/job/%JOB_NAME%/lastBuild/stop"

...which stops the most recent build without any future config editing. All you need is your user/pass combo.

Presage answered 22/9, 2014 at 17:22 Comment(1)
If you don't want to put a clear-text password into a shell script, you can replace <PASS> with the user's API token. Still not great security, but slightly better. (Source: wiki.jenkins-ci.org/display/JENKINS/…)Toulouselautrec

© 2022 - 2024 — McMap. All rights reserved.