Skip to content
Permalink
Browse files

[JENKINS-24380] Stop relying on the format of Run.id.

  • Loading branch information
jglick committed Dec 15, 2014
1 parent 4de329c commit 9a44c001e80cb5575aae92db53642667fd419e6c
@@ -10,7 +10,6 @@
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;
@@ -31,13 +30,8 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.text.DateFormat;
import java.text.ParseException;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.TimeZone;
import java.util.logging.Level;
import java.util.logging.Logger;

@@ -167,52 +161,11 @@ public void doAcceptBuild(StaplerRequest req, StaplerResponse rsp)
removeTriggers(project);
}

String publisherTimezoneID = (String)req.getHeader("X-Publisher-Timezone");
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());
LOGGER.fine("Remote timezone " + publisherTimezone);
}
String buildNumber = req.getHeader("X-Build-Number");

try {
if(publisherTimezone!=null) {
try {
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);
}
}

untar.execute();

if(publisherTimezone!=null) {
File oldBuildDir = new File(buildsDir, buildId);
File newBuildDir = new File(buildsDir, newId);

LOGGER.info("Renaming: " + oldBuildDir.getCanonicalPath() + " to " + newBuildDir.getCanonicalPath());

oldBuildDir.renameTo(newBuildDir);
} else {
LOGGER.info("No remote timezone found");
}

//Load incoming builds from disk
reloadProject(project);

@@ -231,9 +184,6 @@ public void doAcceptBuild(StaplerRequest req, StaplerResponse rsp)
int nextBuildNumber = (lastBuild != null ? lastBuild.number : 0) + 1;
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();
@@ -26,7 +26,6 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.TimeZone;
import java.util.logging.Level;
import org.apache.commons.httpclient.HttpException;

@@ -72,8 +71,6 @@ public void sendBuild(AbstractBuild build, HudsonInstance hudsonInstance)
method.setRequestEntity(new FileRequestEntity(tempFile,
"application/x-tar"));

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 9a44c00

Please sign in to comment.
You can’t perform that action at this time.