diff --git a/src/main/java/hudson/plugins/s3/Entry.java b/src/main/java/hudson/plugins/s3/Entry.java index 65ee36d3..3fcea2c3 100644 --- a/src/main/java/hudson/plugins/s3/Entry.java +++ b/src/main/java/hudson/plugins/s3/Entry.java @@ -40,6 +40,11 @@ public final class Entry implements Describable { */ public boolean noUploadOnFailure; + /** + * Fail the build if no files were uploaded. + */ + public boolean failNoFilesToUpload; + /** * Upload either from the slave or the master */ diff --git a/src/main/java/hudson/plugins/s3/S3BucketPublisher.java b/src/main/java/hudson/plugins/s3/S3BucketPublisher.java index b1766dc8..687d8b9b 100644 --- a/src/main/java/hudson/plugins/s3/S3BucketPublisher.java +++ b/src/main/java/hudson/plugins/s3/S3BucketPublisher.java @@ -118,7 +118,6 @@ public boolean perform(AbstractBuild build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException { - final boolean buildFailed = build.getResult() == Result.FAILURE; S3Profile profile = getProfile(); @@ -151,6 +150,11 @@ public boolean perform(AbstractBuild build, String error = ws.validateAntFileMask(expanded); if (error != null) log(listener.getLogger(), error); + + if (entry.failNoFilesToUpload) { + log(listener.getLogger(), "Marking build unstable because no file(s) were found."); + build.setResult(Result.UNSTABLE); + } } int searchPathLength = getSearchPathLength(ws.getRemote(), expanded); @@ -173,6 +177,7 @@ public boolean perform(AbstractBuild build, log(listener.getLogger(), "bucket=" + bucket + ", file=" + src.getName() + " region=" + selRegion + ", upload from slave=" + entry.uploadFromSlave + " managed="+ entry.managedArtifacts + " , server encryption "+entry.useServerSideEncryption); records.add(profile.upload(build, listener, bucket, src, searchPathLength, escapedUserMetadata, storageClass, selRegion, entry.uploadFromSlave, entry.managedArtifacts, entry.useServerSideEncryption, entry.flatten)); } + if (entry.managedArtifacts) { artifacts.addAll(records); @@ -196,6 +201,7 @@ public boolean perform(AbstractBuild build, e.printStackTrace(listener.error("Failed to upload files")); build.setResult(Result.UNSTABLE); } + return true; } diff --git a/src/main/webapp/help-no-files-upload-failure.html b/src/main/webapp/help-no-files-upload-failure.html new file mode 100644 index 00000000..2d6795f2 --- /dev/null +++ b/src/main/webapp/help-no-files-upload-failure.html @@ -0,0 +1,3 @@ +
+ Mark the build as unstable if no files were uploaded. +