Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I prevent two pipeline jenkins jobs of the same type to run in parallel on the same node?

I do not want to allow two jobs of the same type (same repository) to run in parallel on the same node.

How can I do this using groovy inside Jenkinsfile ?

like image 868
sorin Avatar asked Apr 06 '16 14:04

sorin


People also ask

How can you prevent from several pipeline jobs of the same type to run in parallel on the same node?

Fire the pipeline below twice, one immediately after the other and you will see. You can do this manually by double-clicking "Build Now" or by invoking it from a parallel step in another job.

How do I stop parallel builds in Jenkins?

Disable concurrent builds in Jenkins declarative pipeline. Define disableConcurrentBuilds option to disallow concurrent executions.

Does Jenkins can execute jobs in parallel?

Parallel Job Execution in Jenkins In Jenkins, there are several ways to implement parallel job execution. One of the common approaches is the parent-child build model. In this model – a parent (upstream) job is triggering child (downstream) jobs.


2 Answers

The answer provided in https://stackoverflow.com/a/43963315/6839445 is deprecated.

The current method to disable concurrent builds is to set options:

options { disableConcurrentBuilds() }

Detailed description is available here: https://jenkins.io/doc/book/pipeline/syntax/#options

like image 68
M0nt3c1t0 Avatar answered Oct 23 '22 15:10

M0nt3c1t0


You got at the disableConcurrentBuilds property:

properties properties: [
  ...
  disableConcurrentBuilds(),
  ...
]

Then the job would wait the older one to finish first

like image 24
hypery2k Avatar answered Oct 23 '22 13:10

hypery2k