Issue
I have a Jenkins pipeline that automatically builds the latest code from a Git repository whenever there's a code update. The problem is that sometimes there are 2 or more code updates happening at (almost) the same time, which causes 2 builds to run in parallel.
I assume this won't happen if I set the number of executors in my node to 1, but I don't want to do that.
Is there any way to make sure a build only starts when previous build (of the same job/pipeline) is finished?
Solution
Yes, you can use disableConcurrentBuilds() as given below in your Jenkins file:-
options {
// Disallow concurrent executions of the Pipeline. Can be useful
// for preventing simultaneous accesses to shared resources, etc.
disableConcurrentBuilds()
}
Answered By - user_9090
Answer Checked By - Terry (JavaFixing Volunteer)