Skip to content

Commit

Permalink
[JENKINS-37327] allow empty stash.
Browse files Browse the repository at this point in the history
  • Loading branch information
iwarapter committed Apr 23, 2017
1 parent a3978f9 commit 9b2d10a
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -86,7 +86,7 @@
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-api</artifactId>
<version>2.8</version>
<version>2.14-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
Expand Down
Expand Up @@ -50,6 +50,7 @@ public class StashStep extends Step {
private @CheckForNull String includes;
private @CheckForNull String excludes;
private boolean useDefaultExcludes = true;
private boolean allowEmpty = false;

@DataBoundConstructor public StashStep(@Nonnull String name) {
Jenkins.checkGoodName(name);
Expand Down Expand Up @@ -84,6 +85,14 @@ public boolean isUseDefaultExcludes() {
this.useDefaultExcludes = useDefaultExcludes;
}

public boolean isAllowEmpty() {
return allowEmpty;
}

@DataBoundSetter public void setAllowEmpty(boolean allowEmpty) {
this.allowEmpty = allowEmpty;
}

@Override public StepExecution start(StepContext context) throws Exception {
return new Execution(this, context);
}
Expand All @@ -101,7 +110,7 @@ public static class Execution extends SynchronousNonBlockingStepExecution<Void>

@Override protected Void run() throws Exception {
StashManager.stash(getContext().get(Run.class), step.name, getContext().get(FilePath.class), getContext().get(TaskListener.class), step.includes, step.excludes,
step.useDefaultExcludes);
step.useDefaultExcludes, step.allowEmpty);
return null;
}

Expand Down
Expand Up @@ -37,4 +37,7 @@ THE SOFTWARE.
<f:entry field="useDefaultExcludes" title="Use Default Ant Excludes">
<f:checkbox default="true" />
</f:entry>
<f:entry field="allowEmpty" title="Allow empty stash">
<f:checkbox default="false" />
</f:entry>
</j:jelly>
Expand Up @@ -92,4 +92,22 @@ public class StashTest {
r.assertLogContains("gitignore exists? true", b);
r.assertLogContains("gitignore does not exist? false", b);
}

@Issue("JENKINS-37327")
@Test public void testAllowEmpty() throws Exception {
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
p.setDefinition(new CpsFlowDefinition(
"node {\n" +
" stash name: 'whatever', allowEmpty: true\n" +
" semaphore 'ending'\n" +
"}\n"
, true));
WorkflowRun b = p.scheduleBuild2(0).waitForStart();
SemaphoreStep.waitForStart("ending/1", b);
assertEquals("{whatever={}}", StashManager.stashesOf(b).toString());
SemaphoreStep.success("ending/1", null);
r.assertBuildStatusSuccess(r.waitForCompletion(b));
r.assertLogContains("Stashed 0 file(s)", b);
assertEquals("{}", StashManager.stashesOf(b).toString());
}
}

0 comments on commit 9b2d10a

Please sign in to comment.