Skip to content

Commit

Permalink
Merge pull request #42 from iwarapter/master
Browse files Browse the repository at this point in the history
[JENKINS-37327] allow empty stash.
  • Loading branch information
jglick committed May 30, 2017
2 parents 37d4589 + 261ee58 commit e4266ac
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 3 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Expand Up @@ -63,7 +63,7 @@
</pluginRepositories>
<properties>
<jenkins.version>1.642.3</jenkins.version>
<workflow-step-api-plugin.version>2.9</workflow-step-api-plugin.version>
<workflow-step-api-plugin.version>2.10</workflow-step-api-plugin.version>
<workflow-cps-plugin.version>2.30</workflow-cps-plugin.version>
<workflow-support-plugin.version>2.14</workflow-support-plugin.version>
</properties>
Expand All @@ -88,7 +88,7 @@
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-api</artifactId>
<version>2.11</version>
<version>2.16</version>
<exclusions>
<exclusion>
<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 e4266ac

Please sign in to comment.