Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #35 from iwarapter/master
[JENKINS-37327] allow empty stash.
  • Loading branch information
jglick committed May 30, 2017
2 parents 8c74d21 + 9e3a0d0 commit b19922c
Showing 1 changed file with 10 additions and 3 deletions.
Expand Up @@ -74,7 +74,13 @@ public class StashManager {
@Deprecated
public static void stash(@Nonnull Run<?,?> build, @Nonnull String name, @Nonnull FilePath workspace, @Nonnull TaskListener listener,
@CheckForNull String includes, @CheckForNull String excludes) throws IOException, InterruptedException {
stash(build, name, workspace, listener, includes, excludes, true);
stash(build, name, workspace, listener, includes, excludes, true, false);
}

@Deprecated
public static void stash(@Nonnull Run<?,?> build, @Nonnull String name, @Nonnull FilePath workspace, @Nonnull TaskListener listener,
@CheckForNull String includes, @CheckForNull String excludes, boolean useDefaultExcludes) throws IOException, InterruptedException {
stash(build, name, workspace, listener, includes, excludes, useDefaultExcludes, false);
}

/**
Expand All @@ -85,10 +91,11 @@ public static void stash(@Nonnull Run<?,?> build, @Nonnull String name, @Nonnull
* @param includes a set of Ant-style file includes, separated by commas; null/blank is allowed as a synonym for {@code **} (i.e., everything)
* @param excludes an optional set of Ant-style file excludes
* @param useDefaultExcludes whether to use Ant default excludes
* @param allowEmpty whether to allow an empty stash
*/
@SuppressFBWarnings(value="RV_RETURN_VALUE_IGNORED_BAD_PRACTICE", justification="fine if mkdirs returns false")
public static void stash(@Nonnull Run<?,?> build, @Nonnull String name, @Nonnull FilePath workspace, @Nonnull TaskListener listener,
@CheckForNull String includes, @CheckForNull String excludes, boolean useDefaultExcludes) throws IOException, InterruptedException {
@CheckForNull String includes, @CheckForNull String excludes, boolean useDefaultExcludes, boolean allowEmpty) throws IOException, InterruptedException {
Jenkins.checkGoodName(name);
File storage = storage(build, name);
storage.getParentFile().mkdirs();
Expand All @@ -98,7 +105,7 @@ public static void stash(@Nonnull Run<?,?> build, @Nonnull String name, @Nonnull
OutputStream os = new FileOutputStream(storage);
try {
int count = workspace.archive(ArchiverFactory.TARGZ, os, new DirScanner.Glob(Util.fixEmpty(includes) == null ? "**" : includes, excludes, useDefaultExcludes));
if (count == 0) {
if (count == 0 && !allowEmpty) {
throw new AbortException("No files included in stash");
}
listener.getLogger().println("Stashed " + count + " file(s)");
Expand Down

0 comments on commit b19922c

Please sign in to comment.