Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Permit uploading artifacts for aborted builds #132

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
16 changes: 15 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;

/**
* Upload either from the slave or the master
*/
Expand Down Expand Up @@ -90,9 +95,17 @@ public final class Entry implements Describable<Entry> {
*/
public List<MetadataPair> 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<MetadataPair> userMetadata) {
this.bucket = bucket;
Expand All @@ -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;
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, true, false, true, false, false, false, false, false, null);
}

private Builder stepCreatingFile(String fileName) {
Expand Down