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 ?
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.
Disable concurrent builds in Jenkins declarative pipeline. Define disableConcurrentBuilds option to disallow concurrent executions.
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.
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
You got at the disableConcurrentBuilds property:
properties properties: [
...
disableConcurrentBuilds(),
...
]
Then the job would wait the older one to finish first
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With