提交 52cc5f85 编写于 作者: D Daniel Beck

Merge pull request #2223 from kzantow/JENKINS-34035-easy-skip-setup-wizard

[FIXED JENKINS-34035] - honor jenkins.install.runSetupWizard=false
......@@ -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;
}
......
......@@ -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();
}
/**
......
......@@ -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?
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册