Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[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
kel authored and oleg-nenashev committed Sep 22, 2017
1 parent 5e84c54 commit 27569a9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
6 changes: 3 additions & 3 deletions core/src/main/java/jenkins/model/Jenkins.java
Expand Up @@ -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());
}
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions test/src/test/java/jenkins/install/InstallUtilTest.java
Expand Up @@ -23,7 +23,6 @@
*/
package jenkins.install;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
Expand Down Expand Up @@ -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));

Expand Down Expand Up @@ -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());
}

/**
Expand Down
16 changes: 16 additions & 0 deletions test/src/test/java/jenkins/model/JenkinsTest.java
Expand Up @@ -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;
Expand Down Expand Up @@ -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.