Skip to content
Permalink
Browse files

[Fix JENKINS-42577] Save jenkins version in Jenkins.save() (#3010)

* [Fix JENKINS-42577] Save jenkins version in Jenkins.save()

* [Fix JENKINS-42577] Fix unit test failures
  • Loading branch information...
liketic authored and oleg-nenashev committed Sep 22, 2017
1 parent 5e84c54 commit 27569a965a80caa1352e67c255065b5a67cb1a27
@@ -3181,6 +3181,8 @@ public void run(Reactor session) throws Exception {
*/
public synchronized void save() throws IOException {
if(BulkChange.contains(this)) return;
version = VERSION;

getConfigFile().write(this);
SaveableListener.fireOnChange(this, getConfigFile());
}
@@ -3658,9 +3660,7 @@ public synchronized void doConfigSubmit( StaplerRequest req, StaplerResponse rsp
boolean result = true;
for (Descriptor<?> d : Functions.getSortedDescriptorsForGlobalConfigUnclassified())
result &= configureDescriptor(req,json,d);

version = VERSION;


save();
updateComputerList();
if(result)
@@ -23,7 +23,6 @@
*/
package jenkins.install;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
@@ -81,6 +80,9 @@ public void tearDown() {
*/
@Test
public void test_typeTransitions() {
InstallUtil.getLastExecVersionFile().delete();
InstallUtil.getConfigFile().delete();

// A new test instance sets up security first
Assert.assertEquals(InstallState.INITIAL_SECURITY_SETUP, InstallUtil.getNextInstallState(InstallState.UNKNOWN));

@@ -127,12 +129,10 @@ public void test_getLastExecVersion() throws Exception {
}

private void setStoredVersion(String version) throws Exception {
Field versionField = Jenkins.class.getDeclaredField("version");
versionField.setAccessible(true);
versionField.set(jenkinsRule.jenkins, version);
Assert.assertEquals(version, Jenkins.getStoredVersion().toString());
Jenkins.VERSION = version;
// Force a save of the config.xml
jenkinsRule.jenkins.save();
Assert.assertEquals(version, Jenkins.getStoredVersion().toString());
}

/**
@@ -62,6 +62,7 @@
import hudson.slaves.DumbSlave;
import hudson.slaves.OfflineCause;
import hudson.util.FormValidation;
import hudson.util.VersionNumber;

import org.junit.Rule;
import org.junit.Test;
@@ -601,4 +602,19 @@ public void agentProtocols_singleDisable_roundtrip() throws Exception {
assertThat(protocolToDisable2 + " must be disabled after the roundtrip",
j.jenkins.getAgentProtocols(), not(hasItem(protocolToDisable2)));
}

@Issue("JENKINS-42577")
@Test
public void versionIsSavedInSave() throws Exception {
Jenkins.VERSION = "1.0";
j.jenkins.save();
VersionNumber storedVersion = Jenkins.getStoredVersion();
assertNotNull(storedVersion);
assertEquals(storedVersion.toString(), "1.0");

Jenkins.VERSION = null;
j.jenkins.save();
VersionNumber nullVersion = Jenkins.getStoredVersion();
assertNull(nullVersion);
}
}

0 comments on commit 27569a9

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