diff --git a/src/main/java/hudson/plugins/s3/Entry.java b/src/main/java/hudson/plugins/s3/Entry.java index 63f95cc6..10da6db1 100644 --- a/src/main/java/hudson/plugins/s3/Entry.java +++ b/src/main/java/hudson/plugins/s3/Entry.java @@ -49,6 +49,11 @@ public final class Entry implements Describable { */ public boolean noUploadOnFailure; + /** + * Do not publish the artifacts when build is aborted + */ + public Boolean noUploadOnAborted; + /** * Upload either from the slave or the master */ @@ -90,9 +95,17 @@ public final class Entry implements Describable { */ public List userMetadata; + protected Object readResolve() { + // We need to set noUploadOnAborted to true for backwards compatibility. + if (noUploadOnAborted == null) { + noUploadOnAborted = true; + } + return this; + } + @DataBoundConstructor public Entry(String bucket, String sourceFile, String excludedFile, String storageClass, String selectedRegion, - boolean noUploadOnFailure, boolean uploadFromSlave, boolean managedArtifacts, + boolean noUploadOnFailure, boolean noUploadOnAborted, boolean uploadFromSlave, boolean managedArtifacts, boolean useServerSideEncryption, boolean flatten, boolean gzipFiles, boolean keepForever, boolean showDirectlyInBrowser, List userMetadata) { this.bucket = bucket; @@ -101,6 +114,7 @@ public Entry(String bucket, String sourceFile, String excludedFile, String stora this.storageClass = storageClass; this.selectedRegion = selectedRegion; this.noUploadOnFailure = noUploadOnFailure; + this.noUploadOnAborted = noUploadOnAborted; this.uploadFromSlave = uploadFromSlave; this.managedArtifacts = managedArtifacts; this.useServerSideEncryption = useServerSideEncryption; diff --git a/src/main/java/hudson/plugins/s3/S3BucketPublisher.java b/src/main/java/hudson/plugins/s3/S3BucketPublisher.java index 55e05f81..4983c49e 100644 --- a/src/main/java/hudson/plugins/s3/S3BucketPublisher.java +++ b/src/main/java/hudson/plugins/s3/S3BucketPublisher.java @@ -219,10 +219,6 @@ private void log(final Level level, final PrintStream logger, final String messa public void perform(@Nonnull Run run, @Nonnull FilePath ws, @Nonnull Launcher launcher, @Nonnull TaskListener listener) throws InterruptedException, IOException { final PrintStream console = listener.getLogger(); - if (Result.ABORTED.equals(run.getResult())) { - log(Level.SEVERE, console, "Skipping publishing on S3 because build aborted"); - return; - } if (run.isBuilding()) { log(console, "Build is still running"); @@ -253,6 +249,12 @@ public void perform(@Nonnull Run run, @Nonnull FilePath ws, @Nonnull Launc continue; } + if (entry.noUploadOnAborted && Result.ABORTED.equals(run.getResult())) { + log(Level.SEVERE, console, "Skipping publishing on S3 because build aborted"); + return; + } + + final String expanded = Util.replaceMacro(entry.sourceFile, envVars); final String exclude = Util.replaceMacro(entry.excludedFile, envVars); if (expanded == null) { diff --git a/src/main/resources/hudson/plugins/s3/Entry/config.jelly b/src/main/resources/hudson/plugins/s3/Entry/config.jelly index 7046a7ed..7761072d 100644 --- a/src/main/resources/hudson/plugins/s3/Entry/config.jelly +++ b/src/main/resources/hudson/plugins/s3/Entry/config.jelly @@ -19,6 +19,9 @@ + + + diff --git a/src/test/java/hudson/plugins/s3/S3Test.java b/src/test/java/hudson/plugins/s3/S3Test.java index 3c5038c2..650b2406 100644 --- a/src/test/java/hudson/plugins/s3/S3Test.java +++ b/src/test/java/hudson/plugins/s3/S3Test.java @@ -102,7 +102,7 @@ public void dontSetBuildResultTest() throws Exception { } private Entry entryForFile(String fileName) { - return new Entry("bucket", fileName, "", "", "", false, false, true, false, false, false, false, false, null); + return new Entry("bucket", fileName, "", "", "", false, true, false, true, false, false, false, false, false, null); } private Builder stepCreatingFile(String fileName) {