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

[FIXED JENKINS-24576] Feature to mark build unstable when no files uploaded #37

Open
wants to merge 2 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
5 changes: 5 additions & 0 deletions src/main/java/hudson/plugins/s3/Entry.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ public final class Entry implements Describable<Entry> {
*/
public boolean noUploadOnFailure;

/**
* Fail the build if no files were uploaded.
*/
public boolean failNoFilesToUpload;
Copy link
Member

Choose a reason for hiding this comment

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

Where is the code, which initializes this variable?

Copy link
Member

Choose a reason for hiding this comment

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

I'm not a big fan of public non-final fields due to all kinds of concurrency issues and potential misusages, but it does not increase the technical debt in this class.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think I messed up the merge commit. It looks like that reverted the code change in the config.jelly file.


/**
* Upload either from the slave or the master
*/
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/hudson/plugins/s3/S3BucketPublisher.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand All @@ -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);

Expand All @@ -196,6 +201,7 @@ public boolean perform(AbstractBuild<?, ?> build,
e.printStackTrace(listener.error("Failed to upload files"));
build.setResult(Result.UNSTABLE);
}

return true;
}

Expand Down
3 changes: 3 additions & 0 deletions src/main/webapp/help-no-files-upload-failure.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div>
Mark the build as unstable if no files were uploaded.
</div>