3

I've got a job that need to stop other running\pending jobs when its being run.

Is it possible to do automatically?

Avi Rosenfeld
  • 305
  • 3
  • 7
  • 19
  • You could execute a shell command which in turn will cancel a certain item like this `curl --data '' 'http://example.com:8080/queue/cancelItem?id='`. I also think you can use the `Groovy` plugin and write a small script to cancel specific builds: `jobName = Thread.currentThread().executable.toString().split()[0]; for (item in hudson.model.Hudson.instance.getQueue().getItems()) { if (jobName.equals(item.task.getName())) { println("Aborting current build due to a more recent build request."); hudson.model.Executor.currentExecutor().interrupt(); break; } }` – Cyclonecode Jun 28 '15 at 07:43
  • You can stop running or queued build via Rest API like [this](http://stackoverflow.com/a/21022672/1586762) – Vitalii Elenhaupt Jun 29 '15 at 08:08

2 Answers2

2

This is an old question, but I just spent a bunch of time looking for an answer, hopefully this will save someone time:

Use the jenkins http api to stop a build: wget http://your.jenkins.host/job/JOBNAME/lastBuild/stop

If you are using matrix permissions, make sure your Anonymous user has Read and Cancel permission on Jobs.

Boababa
  • 21
  • 2
-2

There is a plugin available to kill another job.

You can use this plugin :

https://wiki.jenkins-ci.org/display/JENKINS/Signal+killer

This plugin extends ProcessKiller extension point and sends signal (currentlly SIGKILL) to given job via native GNU C library call.