0

I have two Jenkins jobs, COMPILE and TEST, COMPILE triggers TEST, COMPILE is quick, TEST is slow. COMPILE re-creates data which is used by TEST, so if COMPILE runs while TEST is running, TEST might fail due to the necessary data being temporarily unavailable or incomplete.

Sometimes, COMPILE gets triggered a lot (via CMS, busy development). The standard way would be to synchronize COMPILE and TEST via a lock, so that both never run at the same time but instead wait for the other to finish before starting. This waiting does not really suit me as it delays the COMPILE jobs too much.

An alternative might be to turn TEST to concurrent running, but in my case TEST requires too many resources to be able to run concurrently.

So my approach now is to configure COMPILE so that it first aborts a running TEST job (in case one is running) and then starts its work (eventually triggering TEST again in the end). Several quickly performed COMPILE builds will then each start a TEST build which will all be aborted (gray bubble). Only the last TEST build will be completed and show a decent red or green (or yellow) bubble. But that will be enough in my case (and I accept the drawback that this way I cannot detect exactly which commit broke the build).

Now the question is: How can I make COMPILE abort a TEST build? (Preferably in an elegant way.)

I only found a way to generally abort a job from the outside using Jenkins's REST interface, but that doesn't seem to be very elegant. Is there a more elegant way, maybe using a Jenkins-internal feature I don't know or maybe by using a suitable plugin?

Devon M
  • 751
  • 2
  • 9
  • 24
Alfe
  • 56,346
  • 20
  • 107
  • 159
  • You can cancel jobs through the Groovy API. See example here: [Cancel queued builds and aborting executing builds using Groovy for Jenkins][1] [1]: http://stackoverflow.com/questions/12305244/cancel-queued-builds-and-aborting-executing-builds-using-groovy-for-jenkins – Owbea May 04 '15 at 12:21

2 Answers2

0

I would suggest consolidating the two jobs into a single job. That would allow for multiple simultaneous executions and will still fail if the compile fails.

Paul V
  • 123
  • 1
  • 6
  • 1
    But it would have several drawbacks and now advantage in the direction I'm aiming at. I would not be able to distinguish (at a glance) between "actions of C fail" and "actions of T fail" and I would never have the speedup of running the quick C several times in a row without being delayed by the slow T. – Alfe May 05 '15 at 14:04
  • https://wiki.jenkins.io/display/JENKINS/Conditional+BuildStep+Plugin will allow you to only run TEST when certain conditions are met. – markA Oct 03 '17 at 21:07
0

You can set the number of Executors for the node to "1" . By this we can make sure only one jobs run at a time in the node , even if it is executed in parallel it will wait for the 1st job to complete and then start the second