提交 8affa6d9 编写于 作者: E Emanuele Zattin 提交者: Kohsuke Kawaguchi

[FIXED JENKINS-11563]

It would be better to find out why the nextBuildNumber is at times empty.
In the mean time this will find the appropriate number and write it to the file.
上级 b20ef418
......@@ -66,6 +66,9 @@ Upcoming changes</a>
<li class=bug>
Repeated ids, expandTextArea() and multiple "Invoke Ant" build steps.
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-10989">issue 10989</a>)
<li class=bug>
Improve the resilience to the missing 'nextBuildNumber' file.
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-11563">issue 11563</a>)
<li class=bug>
NPE when running Maven 3 jobs with -T.
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-11458">issue 11458</a>)
......
......@@ -23,6 +23,8 @@
*/
package hudson.model;
import com.google.common.base.Function;
import com.google.common.collect.Collections2;
import com.infradna.tool.bridge_method_injector.WithBridgeMethods;
import hudson.Extension;
import hudson.ExtensionPoint;
......@@ -78,18 +80,10 @@ import org.kohsuke.stapler.export.Exported;
import javax.servlet.ServletException;
import java.awt.*;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.*;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;
import java.util.*;
import java.util.List;
import java.util.Map;
import java.util.SortedMap;
import static javax.servlet.http.HttpServletResponse.*;
......@@ -166,7 +160,24 @@ public abstract class Job<JobT extends Job<JobT, RunT>, RunT extends Run<JobT, R
this.nextBuildNumber = Integer.parseInt(f.readTrim());
}
} catch (NumberFormatException e) {
throw new IOException2(f + " doesn't contain a number", e);
// try to infer the value of the next build number from the existing build records. See JENKINS-11563
File[] folders = this.getBuildDir().listFiles(new FileFilter() {
public boolean accept(File file) {
return file.isDirectory() && file.getName().matches("[0-9]+");
}
});
if (folders == null || folders.length == 0) {
this.nextBuildNumber = 1;
} else {
Collection<Integer> foldersInt = Collections2.transform(Arrays.asList(folders), new Function<File, Integer>() {
public Integer apply(File file) {
return Integer.parseInt(file.getName());
}
});
this.nextBuildNumber = Collections.max(foldersInt) + 1;
}
saveNextBuildNumber();
}
} else {
// From the old Hudson, or doCreateItem. Create this file now.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册