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

I create a field to add the file to S3 with other name #71

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
1 change: 1 addition & 0 deletions CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @geofusion/techleads
10 changes: 9 additions & 1 deletion src/main/java/hudson/plugins/s3/Entry.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ public final class Entry implements Describable<Entry> {
* Can contain macros and wildcards.
*/
public String sourceFile;

/**
* File name in the S3
* This is optional
*/
public String destinationFile;

/**
* options for x-amz-storage-class can be STANDARD or REDUCED_REDUNDANCY
*/
Expand Down Expand Up @@ -61,11 +68,12 @@ public final class Entry implements Describable<Entry> {
public boolean flatten;

@DataBoundConstructor
public Entry(String bucket, String sourceFile, String storageClass, String selectedRegion,
public Entry(String bucket, String sourceFile, String destinationFile, String storageClass, String selectedRegion,
boolean noUploadOnFailure, boolean uploadFromSlave, boolean managedArtifacts,
boolean useServerSideEncryption, boolean flatten) {
this.bucket = bucket;
this.sourceFile = sourceFile;
this.destinationFile = destinationFile;
this.storageClass = storageClass;
this.selectedRegion = selectedRegion;
this.noUploadOnFailure = noUploadOnFailure;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/hudson/plugins/s3/S3BucketPublisher.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ public boolean perform(AbstractBuild<?, ?> build,
List<FingerprintRecord> records = Lists.newArrayList();

for (FilePath src : paths) {
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));
log(listener.getLogger(), "bucket=" + bucket + ", file=" + src.getName() + " destination: " + entry.destinationFile + " region=" + selRegion + ", upload from slave=" + entry.uploadFromSlave + " managed="+ entry.managedArtifacts + " , server encryption "+entry.useServerSideEncryption);
records.add(profile.upload(build, listener, bucket, entry.destinationFile, src, searchPathLength, escapedUserMetadata, storageClass, selRegion, entry.uploadFromSlave, entry.managedArtifacts, entry.useServerSideEncryption, entry.flatten));
}
if (entry.managedArtifacts) {
artifacts.addAll(records);
Expand Down
14 changes: 9 additions & 5 deletions src/main/java/hudson/plugins/s3/S3Profile.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,18 +166,22 @@ public void check() throws Exception {
getClient().listBuckets();
}

public FingerprintRecord upload(AbstractBuild<?,?> build, final BuildListener listener, String bucketName, FilePath filePath, int searchPathLength, List<MetadataPair> userMetadata,
public FingerprintRecord upload(AbstractBuild<?,?> build, final BuildListener listener, String bucketName, String destinationFile, FilePath filePath, int searchPathLength, List<MetadataPair> userMetadata,
String storageClass, String selregion, boolean uploadFromSlave, boolean managedArtifacts,boolean useServerSideEncryption, boolean flatten) throws IOException, InterruptedException {
if (filePath.isDirectory()) {
throw new IOException(filePath + " is a directory");
}

String fileName = null;
if (flatten) {
fileName = filePath.getName();
if (destinationFile == null){
if (flatten) {
fileName = filePath.getName();
} else {
String relativeFileName = filePath.getRemote();
fileName = relativeFileName.substring(searchPathLength);
}
} else {
String relativeFileName = filePath.getRemote();
fileName = relativeFileName.substring(searchPathLength);
fileName = destinationFile;
}

Destination dest = new Destination(bucketName, fileName);
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 @@ -6,6 +6,9 @@
<f:entry title="Destination bucket" field="bucket">
<f:textbox/>
</f:entry>
<f:entry title="Destination File Name" field="destinationFile">
<f:textbox/>
</f:entry>
<f:entry title="Storage class" field="storageClass">
<f:select />
</f:entry>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div>Destination file name. This property is optional</div>