Skip to content

Commit

Permalink
[JENKINS-37438] - method to run setup wizard after Jenkins is modified (
Browse files Browse the repository at this point in the history
  • Loading branch information
kzantow authored and oleg-nenashev committed Aug 20, 2016
1 parent 67347c3 commit 4376fde
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions core/src/main/java/jenkins/install/InstallUtil.java
Expand Up @@ -40,6 +40,7 @@
import javax.inject.Provider;

import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;

Expand Down Expand Up @@ -69,6 +70,7 @@ public class InstallUtil {

// tests need this to be 1.0
private static final VersionNumber NEW_INSTALL_VERSION = new VersionNumber("1.0");
private static final VersionNumber FORCE_NEW_INSTALL_VERSION = new VersionNumber("0.0");

/**
* Simple chain pattern using iterator.next()
Expand Down Expand Up @@ -166,7 +168,7 @@ private static InstallState getDefaultInstallState() {

// Neither the top level config or the lastExecVersionFile have a version
// stored in them, which means it's a new install.
if (lastRunVersion.compareTo(NEW_INSTALL_VERSION) == 0) {
if (FORCE_NEW_INSTALL_VERSION.equals(lastRunVersion) || lastRunVersion.compareTo(NEW_INSTALL_VERSION) == 0) {
Jenkins j = Jenkins.getInstance();

// Allow for skipping
Expand All @@ -181,11 +183,13 @@ private static InstallState getDefaultInstallState() {
}
}

// Edge case: used Jenkins 1 but did not save the system config page,
// the version is not persisted and returns 1.0, so try to check if
// they actually did anything
if (!j.getItemMap().isEmpty() || !j.getNodes().isEmpty()) {
return InstallState.UPGRADE;
if (!FORCE_NEW_INSTALL_VERSION.equals(lastRunVersion)) {
// Edge case: used Jenkins 1 but did not save the system config page,
// the version is not persisted and returns 1.0, so try to check if
// they actually did anything
if (!j.getItemMap().isEmpty() || !j.getNodes().isEmpty()) {
return InstallState.UPGRADE;
}
}

return InstallState.INITIAL_SECURITY_SETUP;
Expand Down Expand Up @@ -227,7 +231,13 @@ public static void saveLastExecVersion() {
File lastExecVersionFile = getLastExecVersionFile();
if (lastExecVersionFile.exists()) {
try {
return FileUtils.readFileToString(lastExecVersionFile);
String version = FileUtils.readFileToString(lastExecVersionFile);
// JENKINS-37438 blank will force the setup
// wizard regardless of current state of the system
if (StringUtils.isBlank(version)) {
return FORCE_NEW_INSTALL_VERSION.toString();
}
return version;
} catch (IOException e) {
LOGGER.log(SEVERE, "Unexpected Error. Unable to read " + lastExecVersionFile.getAbsolutePath(), e);
LOGGER.log(WARNING, "Unable to determine the last running version (see error above). Treating this as a restart. No plugins will be updated.");
Expand Down

0 comments on commit 4376fde

Please sign in to comment.