Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/main/java/hudson/plugins/s3/Entry.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ public final class Entry implements Describable<Entry> {
*/
public boolean noUploadOnFailure;

/**
* Do not publish the artifacts when build is aborted
*/
public boolean noUploadOnAborted;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To the best of my understanding, this needs to be true in order to preserve the backwards compatibility. However, existing configurations will be migrated so this gets set to false (default value for boolean) causing it to change semantics.

Better use Boolean here and do the null -> true conversion in readResolve: https://wiki.jenkins.io/display/JENKINS/Hint+on+retaining+backward+compatibility#Hintonretainingbackwardcompatibility-Scenario:Addinganewfield

Copy link
Author

@wheelerlaw wheelerlaw Aug 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just made those changes. Let me know what you think


/**
* Upload either from the slave or the master
*/
Expand Down Expand Up @@ -92,7 +97,7 @@ public final class Entry implements Describable<Entry> {

@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<MetadataPair> userMetadata) {
this.bucket = bucket;
Expand All @@ -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;
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/hudson/plugins/s3/S3BucketPublisher.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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) {
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/hudson/plugins/s3/Entry/config.jelly
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
<f:entry field="noUploadOnFailure" title="No upload on build failure">
<f:checkbox />
</f:entry>
<f:entry field="noUploadOnAborted" title="No upload on aborted build">
<f:checkbox />
</f:entry>
<f:entry field="uploadFromSlave" title="Publish from Slave">
<f:checkbox />
</f:entry>
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/hudson/plugins/s3/S3Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down