Skip to content

Commit

Permalink
s3Upload returns the S3 URL of the target
Browse files Browse the repository at this point in the history
  • Loading branch information
hoegertn committed Feb 8, 2018
1 parent 09401c9 commit 0a7ecc0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -486,6 +486,7 @@ String result = invokeLambda(
* Use DELETE method for failed stack creation. (*Changed behavior*)
* Use Jenkins proxy config when available
* retrieve all CloudFormation exports (#42)
* s3Upload returns the S3 URL of the target

## 1.21
* Fix: `s3Upload` did not work in Jenkins 2.102+ (#JENKINS-49025)
Expand Down
18 changes: 11 additions & 7 deletions src/main/java/de/taimos/pipeline/aws/S3UploadStep.java
Expand Up @@ -33,7 +33,6 @@

import javax.annotation.Nonnull;

import org.jenkinsci.plugins.workflow.steps.AbstractStepExecutionImpl;
import org.jenkinsci.plugins.workflow.steps.StepContext;
import org.jenkinsci.plugins.workflow.steps.StepDescriptor;
import org.jenkinsci.plugins.workflow.steps.StepExecution;
Expand All @@ -57,6 +56,7 @@
import com.google.common.base.Preconditions;

import de.taimos.pipeline.aws.utils.StepUtils;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import hudson.EnvVars;
import hudson.Extension;
import hudson.FilePath;
Expand Down Expand Up @@ -210,7 +210,7 @@ public String getDisplayName() {
}
}

public static class Execution extends AbstractStepExecutionImpl {
public static class Execution extends StepExecution {

protected static final long serialVersionUID = 1L;

Expand Down Expand Up @@ -265,10 +265,14 @@ public boolean start() throws Exception {

new Thread("s3Upload") {
@Override
@SuppressFBWarnings(value = "REC_CATCH_EXCEPTION", justification = "RuntimeExceptions need to be catched")
public void run() {
try {
TaskListener listener = getContext().get(TaskListener.class);
if (children.size() == 1) {
TaskListener listener = Execution.this.getContext().get(TaskListener.class);
if (children.isEmpty()) {
listener.getLogger().println("Nothing to upload");
Execution.this.getContext().onSuccess(null);
} else if (children.size() == 1) {
FilePath child = children.get(0);
listener.getLogger().format("Uploading %s to s3://%s/%s %n", child.toURI(), bucket, path);
if (!child.exists()) {
Expand All @@ -280,16 +284,16 @@ public void run() {
child.act(new RemoteUploader(Execution.this.step.createS3ClientOptions(), Execution.this.getContext().get(EnvVars.class), listener, bucket, path, metadatas, acl, cacheControl, contentType, kmsId));

listener.getLogger().println("Upload complete");
Execution.this.getContext().onSuccess(null);
} else if (children.size() > 1) {
Execution.this.getContext().onSuccess(String.format("s3://%s/%s", bucket, path));
} else {
List<File> fileList = new ArrayList<>();
listener.getLogger().format("Uploading %s to s3://%s/%s %n", includePathPattern, bucket, path);
for (FilePath child : children) {
child.act(new FeedList(fileList));
}
dir.act(new RemoteListUploader(Execution.this.step.createS3ClientOptions(), Execution.this.getContext().get(EnvVars.class), listener, fileList, bucket, path, metadatas, acl, cacheControl, contentType, kmsId));
listener.getLogger().println("Upload complete");
Execution.this.getContext().onSuccess(null);
Execution.this.getContext().onSuccess(String.format("s3://%s/%s", bucket, path));
}
} catch (Exception e) {
Execution.this.getContext().onFailure(e);
Expand Down

0 comments on commit 0a7ecc0

Please sign in to comment.