Jenkins to not allow the same job to run concurrently on the same node?

11,725

Solution 1

Try Throttle Concurrent Builds Plugin. It allows to throtte the number of concurrent builds of a project running per node or globally. In your case you should set:

  • Maximum Total Concurrent Builds: 0 (= unlimited)
  • Maximum Concurrent Builds Per Node: 1

Solution 2

Last time I have checked, only a single instance of each job can run at a single time, i.e.:

If you press the [build] key twice, the first instance of the job will be executed, and only after it is finished - the next one will start.

Were you actually able to run Job1-Build1 and J1-Build2 at the same time?

Share:
11,725

Related videos on Youtube

Marek Gimza
Author by

Marek Gimza

Updated on September 15, 2022

Comments

  • Marek Gimza
    Marek Gimza over 1 year

    I have 4 nodes and 2 jobs. Any node can run 2 jobs concurrently and any job can be executed concurrently. I want to be able to restrict running the same job concurrently on the same machine. For example:

    Jobs: J1 and J2 nodes: N1,N2,N3 and N4

    I can run J1 and J2 on the same node at the same time. I can run J1 on N1 and N3 at the same time. BUT I do not want to run J1 and another build of J1 on the same node at the same time.

    I have tried "Locks and Latches", "Jenkins Exclusive Execution", "Exclusion Plugin" plugins, and these will work well when trying to coordinate different jobs. But my case is trying to manage different build-instances of the same job.

  • Marek Gimza
    Marek Gimza almost 12 years
    Gonen, thanks for the reply. Yes I can run J1-Build1 and J1-Build2 at the same time. In fact all jobs will run concurrently without any problem. My requirement is to prevent the same job (i.e. J1) from running on the same node: I want to prevent this type of scenario:Run J1-Node1 and another instance of J1-node1. my requirement: While an instance of J1 is already running on Node1 (i.e. J1-Node1), Start the mew instance of J1 on a different node (i.e. J1-Node2) and not on Node1. If Nod2 is also running an instance of J1, then wait! Thanks Marek
  • Gonen
    Gonen almost 12 years
    Marek, you can go to the other extreme, prevent any instance of J1 from starting until all other have finished, thus J1-build2 will not start until J1-build1 is done. Should use the 'Block build when downstream project is building' option (under the Advanced Project Options section).
  • rainbowsprinkles
    rainbowsprinkles about 10 years
    Thank you for specifying that 0 = unlimited! I've bashed my head over wondering why specifying 0 as the maximum total concurrent builds would still lead to concurrent builds, i.e. thinking that 0 = 0. :)