Skip to content

Commit

Permalink
[FIX JENKINS-40894] Restore unstableReturn in readResolve
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-beck committed Jan 10, 2017
1 parent f2a46b8 commit 93467c3
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 2 deletions.
4 changes: 3 additions & 1 deletion core/src/main/java/hudson/tasks/BatchFile.java
Expand Up @@ -81,7 +81,9 @@ protected boolean isErrorlevelForUnstableBuild(int exitCode) {
}

private Object readResolve() throws ObjectStreamException {
return new BatchFile(command);
BatchFile batch = new BatchFile(command);
batch.setUnstableReturn(unstableReturn);
return batch;
}

@Extension @Symbol("batchFile")
Expand Down
4 changes: 3 additions & 1 deletion core/src/main/java/hudson/tasks/Shell.java
Expand Up @@ -125,7 +125,9 @@ public DescriptorImpl getDescriptor() {
}

private Object readResolve() throws ObjectStreamException {
return new Shell(command);
Shell shell = new Shell(command);
shell.setUnstableReturn(unstableReturn);
return shell;
}

@Extension @Symbol("shell")
Expand Down
11 changes: 11 additions & 0 deletions test/src/test/java/hudson/tasks/BatchFileTest.java
@@ -1,5 +1,6 @@
package hudson.tasks;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assume.assumeTrue;

Expand All @@ -16,6 +17,7 @@
import hudson.Proc;
import hudson.model.Result;
import hudson.model.FreeStyleProject;
import org.jvnet.hudson.test.recipes.LocalData;


/**
Expand Down Expand Up @@ -148,4 +150,13 @@ public void windowsUnstableCodeZeroIsSameAsUnset() throws Exception {
/* Creating unstable=0 produces unstable=null */
assertNull( createNewBatchTask("",0).getUnstableReturn() );
}

@Issue("JENKINS-40894")
@Test
@LocalData
public void canLoadUnstableReturnFromDisk() throws Exception {
FreeStyleProject p = (FreeStyleProject) rule.jenkins.getItemByFullName("batch");
BatchFile batchFile = (BatchFile) p.getBuildersList().get(0);
assertEquals("unstable return", Integer.valueOf(1), batchFile.getUnstableReturn());
}
}
10 changes: 10 additions & 0 deletions test/src/test/java/hudson/tasks/ShellTest.java
Expand Up @@ -27,6 +27,7 @@
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.recipes.LocalData;

/**
* Tests for the Shell tasks class
Expand Down Expand Up @@ -190,4 +191,13 @@ public void unixUnstableCodeZeroIsSameAsUnset() throws Exception {
assertNull( createNewShell("",0).getUnstableReturn() );
}

@Issue("JENKINS-40894")
@Test
@LocalData
public void canLoadUnstableReturnFromDisk() throws Exception {
FreeStyleProject p = (FreeStyleProject) rule.jenkins.getItemByFullName("test");
Shell shell = (Shell) p.getBuildersList().get(0);
assertEquals("unstable return", Integer.valueOf(1), shell.getUnstableReturn());
}

}
Binary file not shown.
Binary file not shown.

0 comments on commit 93467c3

Please sign in to comment.