From 073c800f55a0a2e1d861ecc4c6217c5c89752682 Mon Sep 17 00:00:00 2001 From: Cosmin Catalin Sanda Date: Thu, 21 May 2015 23:04:02 +0200 Subject: [PATCH] Add environment variables to S3 prefix setting --- .../amazonaws/codedeploy/AWSCodeDeployPublisher.java | 10 ++++++---- .../AWSCodeDeployPublisher/help-s3prefix.html | 3 ++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/amazonaws/codedeploy/AWSCodeDeployPublisher.java b/src/main/java/com/amazonaws/codedeploy/AWSCodeDeployPublisher.java index 931dcc3..6881460 100644 --- a/src/main/java/com/amazonaws/codedeploy/AWSCodeDeployPublisher.java +++ b/src/main/java/com/amazonaws/codedeploy/AWSCodeDeployPublisher.java @@ -34,6 +34,7 @@ import hudson.FilePath; import hudson.Launcher; import hudson.Extension; +import hudson.Util; import hudson.model.AbstractBuild; import hudson.model.BuildListener; import hudson.model.AbstractProject; @@ -58,6 +59,7 @@ import java.io.IOException; import java.io.PrintStream; import java.util.Date; +import java.util.Map; import java.util.UUID; import javax.servlet.ServletException; @@ -165,7 +167,7 @@ public AWSCodeDeployPublisher( } @Override - public boolean perform(AbstractBuild build, Launcher launcher, BuildListener listener) { + public boolean perform(AbstractBuild build, Launcher launcher, BuildListener listener) throws IOException, InterruptedException { this.logger = listener.getLogger(); final boolean buildFailed = build.getResult() == Result.FAILURE; @@ -205,7 +207,7 @@ public boolean perform(AbstractBuild build, Launcher launcher, BuildListener lis verifyCodeDeployApplication(aws); String projectName = build.getProject().getName(); - RevisionLocation revisionLocation = zipAndUpload(aws, projectName, build.getWorkspace()); + RevisionLocation revisionLocation = zipAndUpload(aws, projectName, build.getWorkspace(), build.getEnvironment(listener)); registerRevision(aws, revisionLocation); String deploymentId = createDeployment(aws, revisionLocation); @@ -243,7 +245,7 @@ private void verifyCodeDeployApplication(AWSClients aws) throws IllegalArgumentE } } - private RevisionLocation zipAndUpload(AWSClients aws, String projectName, FilePath workspace) throws IOException, InterruptedException { + private RevisionLocation zipAndUpload(AWSClients aws, String projectName, FilePath workspace, Map envVars) throws IOException, InterruptedException { File zipFile = File.createTempFile(projectName + "-", ".zip"); this.logger.println("Zipping workspace into " + zipFile.getAbsolutePath()); @@ -257,7 +259,7 @@ private RevisionLocation zipAndUpload(AWSClients aws, String projectName, FilePa if (this.s3prefix.isEmpty()) { key = zipFile.getName(); } else { - key = this.s3prefix; + key = Util.replaceMacro(this.s3prefix, envVars); if (this.s3prefix.endsWith("/")) { key += zipFile.getName(); } else { diff --git a/src/main/resources/com/amazonaws/codedeploy/AWSCodeDeployPublisher/help-s3prefix.html b/src/main/resources/com/amazonaws/codedeploy/AWSCodeDeployPublisher/help-s3prefix.html index 2211ee8..8cbb3d5 100644 --- a/src/main/resources/com/amazonaws/codedeploy/AWSCodeDeployPublisher/help-s3prefix.html +++ b/src/main/resources/com/amazonaws/codedeploy/AWSCodeDeployPublisher/help-s3prefix.html @@ -1,3 +1,4 @@
- The prefix in the S3 Bucket to prepend to the AWS CodeDeploy revision. Default is the root of the bucket. + The prefix in the S3 Bucket to prepend to the AWS CodeDeploy revision. Default is the root of the bucket. You can + use environment variables in this field.