1
votes

I am using Jenkins 1.609 I have a requirement wherein 1) no two jobs can execute simultaneously on the same node but 2) they can execute simultaneously when triggered on different nodes. No of executors configured on all slave nodes is 1.

Default Jenkins behavior: If job A and job B, both are triggered on same node then Job B goes in executor starvation state because build is waiting for "too long" compared to the time it takes to execute it.

Have tried using "Exclusion plugin". It helps in achieving first point but not the second one.

Also, have tried using Throttle concurrent builds plugin but still Job B goes into executor starvation state

Is there any way wherein I can achieve both the points i.e. prevent running the jobs simultaneously on same node but can run on different nodes and without the second job going into executor starvation state as I cannot change the sequence of the jobs.

2

2 Answers

1
votes

You can use following plugin. https://wiki.jenkins-ci.org/display/JENKINS/Exclusion-Plugin

In this plugin you can allocate file as resource for the job which will be created when job starts. Another job will try to use same file as lock resource and will wait for the first one to release it, But it does not depend on Node.

Following Plugin can also be used to release and acquire lock. https://wiki.jenkins-ci.org/display/JENKINS/Locks+and+Latches+plugin

One more way could be, Just write a lock file in temp location and check for the file to make your job force to wait and once that file is gone your job can continue, It can remove the lock file once job is over. This way you can make jobs running on same host and they can run parallel on different nodes.

0
votes

You have already prevented two jobs from running on the same node (slave) by setting the number of executors to 1. To allow two jobs to run on otherwise identical slaves, use a label, restrict slaves under "Usage" to "Only Build Jobs with label expressions matching this node".

So for example add the label "PREFERRED" to both nodes. Then for jobs A and B, set the "Restrict where this job can be run" to "PREFERRED".

Either job can then start on any matching slave and two jobs can run in parallel.

If you increase the number of executors above 1 for any slave, then you will need to use a Lock/Exclusion Plugin.