I have a very specific 'problem' with our Jenkins builds. We have a Jenkins declarative pipeline set up for our projects, the pipeline contains all stages needed for automated testing, releases, ... However, we would like to avoid unnecessary builds and thus we would want to cancel older builds if a new commit was done on a branch. We already investigated the milestone approach but this wasn't enough for us (as far as we see). I'll show the problem with an example:
Let's say build 1 starts of a PR, these are the steps it will take:
- Build the code
- Take a snapshot of our test environment
- Deploy the code to our test environment
- Run all tests
- Restore previously taken snapshot
- Some other steps
With the milestone approach, you have no idea where in the pipeline the older build will get aborted. So, continuing the example:
Let's now say build 2 starts of the PR, and build 1 was in step 4:
Possible problem: snapshot isn't restored (but I think we can fix that by catching the abort exception)
Let's now say build 2 starts when build 1 is in step 5:
Problem: we don't know where in the restore process the build is aborted, so our environment could get corrupted!
So, to conclude: I am looking for a way to either say: from this point on, this build can't be aborted by milestones. Or to 'disable' the milestone aborts for a while, so that build 1 will always finish the snapshot restore before being aborted.
question from:
https://stackoverflow.com/questions/65883159/jenkins-advanced-abort-previous-builds 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…