Skip to content
Permalink
Browse files
Fix for JENKINS-18238
Updated code to create symlink for the build (based on private instances
build number) as well as update the PeepHolePermalinks.

This should resolve:
JENKINS-18238
JENKINS-6096

And may influence:
JENKINS-18105
  • Loading branch information
shermdog committed Apr 30, 2014
1 parent 77680da commit 974eb0135b9830de84d8b9539487e6c42e83cbcc
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
@@ -10,13 +10,16 @@
import hudson.model.Job;
import hudson.model.JobProperty;
import hudson.model.JobPropertyDescriptor;
import hudson.model.PermalinkProjectAction.Permalink;
import hudson.model.Project;
import hudson.model.ProminentProjectAction;
import hudson.model.Result;
import hudson.model.Run;
import hudson.model.AbstractBuild;
import hudson.tasks.ArtifactArchiver;
import hudson.tasks.LogRotator;
import hudson.util.IOException2;
import hudson.util.LogTaskListener;
import net.sf.json.JSONObject;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.taskdefs.Untar;
@@ -168,13 +171,17 @@ public void doAcceptBuild(StaplerRequest req, StaplerResponse rsp)
LOGGER.info("Got remote timezone " + publisherTimezoneID);
TimeZone publisherTimezone = null;
String buildId = null;
String buildNumber = null;
String newId = null;
String symId = null;
DateFormat dateFormatter = null;
DateFormat oldDateFormatter = null;
if(publisherTimezoneID!=null) {
publisherTimezone = TimeZone.getTimeZone(publisherTimezoneID);
dateFormatter = Run.getIDFormatter();
buildId = (String)req.getHeader("X-Build-ID");
buildNumber = (String)req.getHeader("X-Build-Number");
symId = buildId;
oldDateFormatter = (DateFormat)dateFormatter.clone();
oldDateFormatter.setTimeZone(publisherTimezone);
LOGGER.fine("Local timezone " + dateFormatter.getTimeZone());
@@ -187,6 +194,7 @@ public void doAcceptBuild(StaplerRequest req, StaplerResponse rsp)
LOGGER.fine("Original build time " + oldDateFormatter.parse(buildId));
newId = dateFormatter.format(oldDateFormatter.parse(buildId));
LOGGER.fine("New build ID " + newId);
symId = newId;
} catch (ParseException e) {
throw new BuildException("Failed to parse buildId", e);
}
@@ -221,7 +229,53 @@ public void doAcceptBuild(StaplerRequest req, StaplerResponse rsp)
//Update next build number
Run lastBuild = project.getLastBuild();
int nextBuildNumber = (lastBuild != null ? lastBuild.number : 0) + 1;
project.updateNextBuildNumber(nextBuildNumber);
project.updateNextBuildNumber(nextBuildNumber);

//Update build symlink
Util.createSymlink(buildsDir, symId, buildNumber, new LogTaskListener(LOGGER, Level.INFO));

//Update permalink symlinks
if (lastBuild.getResult() == Result.SUCCESS) {
Run<?,?> bid = project.getLastStableBuild();
if (bid != null) {
if(Integer.parseInt(buildNumber) >= bid.number){
Util.createSymlink(buildsDir, buildNumber, "lastStableBuild", new LogTaskListener(LOGGER, Level.INFO));
}
}
}
if (lastBuild.getResult().isBetterOrEqualTo(Result.UNSTABLE)) {
Run<?,?> bid = project.getLastSuccessfulBuild();
if (bid != null) {
if(Integer.parseInt(buildNumber) >= bid.number){
Util.createSymlink(buildsDir, buildNumber, "lastSuccessfulBuild", new LogTaskListener(LOGGER, Level.INFO));
}
}
}
if (lastBuild.getResult() == Result.FAILURE) {
Run<?,?> bid = project.getLastFailedBuild();
if (bid != null) {
if(Integer.parseInt(buildNumber) >= bid.number){
Util.createSymlink(buildsDir, buildNumber, "lastFailedBuild", new LogTaskListener(LOGGER, Level.INFO));
}
}
}
if (lastBuild.getResult() == Result.UNSTABLE) {
Run<?,?> bid = project.getLastUnstableBuild();
if (bid != null) {
if(Integer.parseInt(buildNumber) >= bid.number){
Util.createSymlink(buildsDir, buildNumber, "lastUnstableBuild", new LogTaskListener(LOGGER, Level.INFO));
}
}
}
if (lastBuild.getResult() != Result.SUCCESS) {
Run<?,?> bid = project.getLastUnsuccessfulBuild();
if (bid != null) {
if(Integer.parseInt(buildNumber) >= bid.number){
Util.createSymlink(buildsDir, buildNumber, "lastUnsuccessfulBuild", new LogTaskListener(LOGGER, Level.INFO));
}
}
}

//Add confirmation header
rsp.addHeader("X-Build-Recieved",project.getName());
try {
@@ -74,6 +74,7 @@ public void sendBuild(AbstractBuild build, HudsonInstance hudsonInstance)

method.setRequestHeader("X-Publisher-Timezone", TimeZone.getDefault().getID());
method.setRequestHeader("X-Build-ID", build.getId());
method.setRequestHeader("X-Build-Number", String.valueOf(build.getNumber()));

executeMethod(method, hudsonInstance);

0 comments on commit 974eb01

Please sign in to comment.