From 7804730d2e09c523658fefacc5a9f4c58251b5e7 Mon Sep 17 00:00:00 2001 From: Wheeler Law Date: Thu, 9 Jul 2020 16:10:03 -0400 Subject: [PATCH 1/3] Add a configuration option to permit uploading artifacts when the build is aborted --- src/main/java/hudson/plugins/s3/Entry.java | 8 +++++++- src/main/java/hudson/plugins/s3/S3BucketPublisher.java | 10 ++++++---- .../resources/hudson/plugins/s3/Entry/config.jelly | 3 +++ src/test/java/hudson/plugins/s3/S3Test.java | 2 +- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/main/java/hudson/plugins/s3/Entry.java b/src/main/java/hudson/plugins/s3/Entry.java index 63f95cc6..4d575419 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 */ @@ -92,7 +97,7 @@ public final class Entry implements Describable { @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 +106,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..d15a03b5 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, false, false, true, false, false, false, false, false, null); } private Builder stepCreatingFile(String fileName) { From 8b8362e4c996940864db047a100bc1e005cd4463 Mon Sep 17 00:00:00 2001 From: Wheeler Law Date: Tue, 11 Aug 2020 10:53:42 -0400 Subject: [PATCH 2/3] Set default for noUploadOnAbort to true to preserve backwards compatability --- src/test/java/hudson/plugins/s3/S3Test.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/hudson/plugins/s3/S3Test.java b/src/test/java/hudson/plugins/s3/S3Test.java index d15a03b5..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, 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) { From 15c43a94f10c35b95816740bf812b6b762fa3772 Mon Sep 17 00:00:00 2001 From: Wheeler Law Date: Tue, 11 Aug 2020 11:06:21 -0400 Subject: [PATCH 3/3] Need to use readResolve because the constructor won't be called upon de-serialization --- src/main/java/hudson/plugins/s3/Entry.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/hudson/plugins/s3/Entry.java b/src/main/java/hudson/plugins/s3/Entry.java index 4d575419..10da6db1 100644 --- a/src/main/java/hudson/plugins/s3/Entry.java +++ b/src/main/java/hudson/plugins/s3/Entry.java @@ -52,7 +52,7 @@ public final class Entry implements Describable { /** * Do not publish the artifacts when build is aborted */ - public boolean noUploadOnAborted; + public Boolean noUploadOnAborted; /** * Upload either from the slave or the master @@ -95,6 +95,14 @@ 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 noUploadOnAborted, boolean uploadFromSlave, boolean managedArtifacts,