mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-18 06:22:29 +00:00
[FIXED HUDSON-2417] Taking stability into account when deciding which builds & artifacts to keep.
Previously, Hudson only tried to keep successful builds, meaning it would discard the last stable build if there was a long run of unstable builds. This made .../lastStableBuild/... permalinks useless. Artifact archiver logic with "latest only" also improved more generally: 1. Discards old artifacts at the start of the build. It might as well save the disk space sooner rather than later. 2. Rather than deleting all old artifacts prior to some point, now keeps the latest representatives of different stability classes of build: always keeps last stable if available, and also last successful if newer, and (just in case) also the last failed if that is newer. Formerly it behaved oddly: during a run of failed builds, all of their artifacts would be kept, though these are unlikely to be useful. Also introducing tests for all this functionality, which does not seem to have been tested before. git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@15587 71c3de6d-444a-0410-be80-ed276b4c234a
This commit is contained in:
1 parent
8adda53dc6
commit
277539081b
8 files changed
+264
-11
No files matched your search
@@ -117,13 +117,18 @@ public class ArtifactArchiver extends Publisher {
|
||||
return true;
|
||||
}
|
||||
|
||||
if(latestOnly) {
|
||||
AbstractBuild<?,?> b = p.getLastSuccessfulBuild();
|
||||
if(b!=null) {
|
||||
while(true) {
|
||||
b = b.getPreviousBuild();
|
||||
if(b==null) break;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public @Override boolean prebuild(AbstractBuild<?, ?> build, BuildListener listener) {
|
||||
if(latestOnly) {
|
||||
AbstractBuild<?,?> b = build.getProject().getLastCompletedBuild();
|
||||
Result bestResultSoFar = Result.NOT_BUILT;
|
||||
while(b!=null) {
|
||||
if (b.getResult().isBetterThan(bestResultSoFar)) {
|
||||
bestResultSoFar = b.getResult();
|
||||
} else {
|
||||
// remove old artifacts
|
||||
File ad = b.getArtifactsDir();
|
||||
if(ad.exists()) {
|
||||
@@ -135,9 +140,9 @@ public class ArtifactArchiver extends Publisher {
|
||||
}
|
||||
}
|
||||
}
|
||||
b = b.getPreviousBuild();
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -78,11 +78,12 @@ public class LogRotator implements Describable<LogRotator> {
|
||||
public void perform(Job<?,?> job) throws IOException, InterruptedException {
|
||||
// keep the last successful build regardless of the status
|
||||
Run lsb = job.getLastSuccessfulBuild();
|
||||
Run lstb = job.getLastStableBuild();
|
||||
|
||||
if(numToKeep!=-1) {
|
||||
Run[] builds = job.getBuilds().toArray(new Run[0]);
|
||||
for( int i=numToKeep; i<builds.length; i++ ) {
|
||||
if(!builds[i].isKeepLog() && builds[i]!=lsb)
|
||||
if(!builds[i].isKeepLog() && builds[i]!=lsb && builds[i]!=lstb)
|
||||
builds[i].delete();
|
||||
}
|
||||
}
|
||||
@@ -92,7 +93,7 @@ public class LogRotator implements Describable<LogRotator> {
|
||||
cal.add(Calendar.DAY_OF_YEAR,-daysToKeep);
|
||||
// copy it to the array because we'll be deleting builds as we go.
|
||||
for( Run r : job.getBuilds().toArray(new Run[0]) ) {
|
||||
if(r.getTimestamp().before(cal) && !r.isKeepLog() && r!=lsb)
|
||||
if(r.getTimestamp().before(cal) && !r.isKeepLog() && r!=lsb && r!=lstb)
|
||||
r.delete();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user