Skip to content
Permalink
Browse files
[JENKINS-37438] - method to run setup wizard after Jenkins is modified (
  • Loading branch information
kzantow authored and oleg-nenashev committed Aug 20, 2016
1 parent 67347c3 commit 4376fdedfc85a652f77af098d539e30dd18665fa
Showing with 17 additions and 7 deletions.
  1. +17 −7 core/src/main/java/jenkins/install/InstallUtil.java
@@ -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;

@@ -69,6 +70,7 @@

// 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()
@@ -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
@@ -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;
@@ -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.");

0 comments on commit 4376fde

Please sign in to comment.