My build pipeline in Jenkins is broken down into three jobs:
I have set it up so that concurrent builds can occur and the build pipeline will stop a build from entering #2, if #2 or #3 is currently running for another build.
What I want to be able to do is set up Jenkins to handle when there is more than one build waiting, and #2 and #3 finish, for only the LATEST build to enter into #2 and #3.
Is there a way to do this out of the box? IF you have the book Continuous Delivery, what I'm trying to do is implement what's on p. 118 - p. 119
You can even fail the build and continue the execution of the pipeline. Just make sure your Jenkins is up to date, since this feature is only available since "Pipeline: Basic Steps" 2.16 (May 14, 2019). Before that, catchError is still available but without parameters:
Triggers follow the same logic as the “build after other projects are built” option in the configuration of Jenkins projects. Most teams work with this model because it’s the default option of Jenkins. When we want to use triggers in the pipeline syntax, we simple define the upstream project that we want to monitor and specify our threshold.
Freestyle Project: Freestyle Project in Jenkins is an improvised or unrestricted build job or task with multiple operations. Operations can be a build, pipeline run, or any script run. Maven Project: Maven project is selected for managing as well as building the projects which contain POM files.
However, there are two ways to link Jobs: triggers and the build command. Both have their own strengths and weaknesses and if you only use one of these, you’re definitely missing out. Triggers follow the same logic as the “build after other projects are built” option in the configuration of Jenkins projects.
Should try one of those, under Advanced Project Options:
Block build when upstream project is building
(should make sure it does not cause steps 2 and 3 to get stuck in queue)
Block build when downstream project is building
(I know this one sounds like the opposite to your request,
but the actual result is that you accumulate changes to a single build-cycle,
preventing extra runs)
If this causes unwanted builds to pile-up,
please review the following links that should help you
empty the queue or kill running jobs:
Stopping Jenkins job in case newer one is started (by malenkiy_scot)
Purge Build Queue Plugin
Signal killer
Kill All the Builds (courtesy of Kohsuke Kawaguchi)
import hudson.model.*;
Hudson.instance.computers.each { c ->
c.executors.each { e ->
e.interrupt();
}
}
Cheers
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