diff --git a/core/src/main/java/jenkins/install/InstallUtil.java b/core/src/main/java/jenkins/install/InstallUtil.java index 7468927ffb299f74767d4796320961730a89fa3c..0b7a2d84f571428ecb337859d0615a6b47685d55 100644 --- a/core/src/main/java/jenkins/install/InstallUtil.java +++ b/core/src/main/java/jenkins/install/InstallUtil.java @@ -82,9 +82,14 @@ public class InstallUtil { throw new IllegalStateException("Unknown install state override specified on the commandline: '" + stateOverride + "'."); } } - + + // Support a 3-state flag for running or disabling the setup wizard + String shouldRunFlag = System.getProperty("jenkins.install.runSetupWizard"); + boolean shouldRun = "true".equalsIgnoreCase(shouldRunFlag); + boolean shouldNotRun = "false".equalsIgnoreCase(shouldRunFlag); + // install wizard will always run if environment specified - if (!Boolean.getBoolean("jenkins.install.runSetupWizard")) { + if (!shouldRun) { if (Functions.getIsUnitTest()) { return InstallState.TEST; } @@ -99,10 +104,24 @@ public class InstallUtil { // 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) { + Jenkins j = Jenkins.getInstance(); + + // Allow for skipping + if(shouldNotRun) { + try { + SetupWizard.completeSetup(j); + UpgradeWizard.completeUpgrade(j); + return j.getInstallState(); + } catch (RuntimeException e) { + throw e; + } catch (Exception e) { + throw new RuntimeException(e); + } + } + // 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 - Jenkins j = Jenkins.getInstance(); if (!j.getItemMap().isEmpty() || !mayBeJenkins2SecurityDefaults(j)) { return InstallState.UPGRADE; } diff --git a/core/src/main/java/jenkins/install/SetupWizard.java b/core/src/main/java/jenkins/install/SetupWizard.java index 667ef69bd720950a17ccacd7d813be34b53f664a..b2faacbeb427de98b38989fc58ad796312c28cbf 100644 --- a/core/src/main/java/jenkins/install/SetupWizard.java +++ b/core/src/main/java/jenkins/install/SetupWizard.java @@ -58,10 +58,7 @@ public class SetupWizard { public SetupWizard(Jenkins j) throws IOException, InterruptedException { this.jenkins = j; - // this was determined to be a new install, don't run the update wizard here - UpgradeWizard uw = jenkins.getInjector().getInstance(UpgradeWizard.class); - if (uw!=null) - uw.setCurrentLevel(new VersionNumber("2.0")); + UpgradeWizard.completeUpgrade(j); // Create an admin user by default with a // difficult password @@ -206,13 +203,16 @@ public class SetupWizard { * Remove the setupWizard filter, ensure all updates are written to disk, etc */ public HttpResponse doCompleteInstall() throws IOException, ServletException { + completeSetup(jenkins); + PluginServletFilter.removeFilter(FORCE_SETUP_WIZARD_FILTER); + return HttpResponses.okJSON(); + } + + static void completeSetup(Jenkins jenkins) { jenkins.setInstallState(InstallState.INITIAL_SETUP_COMPLETED); InstallUtil.saveLastExecVersion(); - PluginServletFilter.removeFilter(FORCE_SETUP_WIZARD_FILTER); // Also, clean up the setup wizard if it's completed jenkins.setSetupWizard(null); - - return HttpResponses.okJSON(); } /** diff --git a/core/src/main/java/jenkins/install/UpgradeWizard.java b/core/src/main/java/jenkins/install/UpgradeWizard.java index fcb2aa834102a4f12fcc20f46724d2a651732ae6..b2f47b3b042d2365bfc6c58c4ac292f142255107 100644 --- a/core/src/main/java/jenkins/install/UpgradeWizard.java +++ b/core/src/main/java/jenkins/install/UpgradeWizard.java @@ -71,10 +71,17 @@ public class UpgradeWizard extends PageDecorator { } /*package*/ - public void setCurrentLevel(VersionNumber v) throws IOException { + void setCurrentLevel(VersionNumber v) throws IOException { FileUtils.writeStringToFile(getStateFile(), v.toString()); updateUpToDate(); } + + static void completeUpgrade(Jenkins jenkins) throws IOException { + // this was determined to be a new install, don't run the update wizard here + UpgradeWizard uw = jenkins.getInjector().getInstance(UpgradeWizard.class); + if (uw!=null) + uw.setCurrentLevel(new VersionNumber("2.0")); + } /** * Do we need to show the upgrade wizard prompt?