Skip to content

Commit ecb18e4

Browse files
committed
Merge branch 's3-env-variables' of git://github.com/cosmincatalin/aws-codedeploy-plugin into cosmincatalin-s3-env-variables
Conflicts: src/main/java/com/amazonaws/codedeploy/AWSCodeDeployPublisher.java
2 parents 78e4c4e + 073c800 commit ecb18e4

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

src/main/java/com/amazonaws/codedeploy/AWSCodeDeployPublisher.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import hudson.FilePath;
3535
import hudson.Launcher;
3636
import hudson.Extension;
37+
import hudson.Util;
3738
import hudson.model.AbstractBuild;
3839
import hudson.model.BuildListener;
3940
import hudson.model.AbstractProject;
@@ -58,6 +59,7 @@
5859
import java.io.IOException;
5960
import java.io.PrintStream;
6061
import java.util.Date;
62+
import java.util.Map;
6163
import java.util.UUID;
6264

6365
import javax.servlet.ServletException;
@@ -168,7 +170,7 @@ public AWSCodeDeployPublisher(
168170
}
169171

170172
@Override
171-
public boolean perform(AbstractBuild build, Launcher launcher, BuildListener listener) {
173+
public boolean perform(AbstractBuild build, Launcher launcher, BuildListener listener) throws IOException, InterruptedException {
172174

173175
this.logger = listener.getLogger();
174176
final boolean buildFailed = build.getResult() == Result.FAILURE;
@@ -208,7 +210,7 @@ public boolean perform(AbstractBuild build, Launcher launcher, BuildListener lis
208210
verifyCodeDeployApplication(aws);
209211

210212
String projectName = build.getProject().getName();
211-
RevisionLocation revisionLocation = zipAndUpload(aws, projectName, getSourceDirectory(build.getWorkspace()));
213+
RevisionLocation revisionLocation = zipAndUpload(aws, projectName, getSourceDirectory(build.getWorkspace()), build.getEnvironment(listener));
212214

213215
registerRevision(aws, revisionLocation);
214216
String deploymentId = createDeployment(aws, revisionLocation);
@@ -270,7 +272,7 @@ private void verifyCodeDeployApplication(AWSClients aws) throws IllegalArgumentE
270272
}
271273
}
272274

273-
private RevisionLocation zipAndUpload(AWSClients aws, String projectName, FilePath sourceDirectory) throws IOException, InterruptedException {
275+
private RevisionLocation zipAndUpload(AWSClients aws, String projectName, FilePath sourceDirectory, Map<String, String> envVars) throws IOException, InterruptedException {
274276

275277
File zipFile = File.createTempFile(projectName + "-", ".zip");
276278
String key;
@@ -286,14 +288,13 @@ private RevisionLocation zipAndUpload(AWSClients aws, String projectName, FilePa
286288
if (this.s3prefix.isEmpty()) {
287289
key = zipFile.getName();
288290
} else {
289-
key = this.s3prefix;
291+
key = Util.replaceMacro(this.s3prefix, envVars);
290292
if (this.s3prefix.endsWith("/")) {
291293
key += zipFile.getName();
292294
} else {
293295
key += "/" + zipFile.getName();
294296
}
295297
}
296-
297298
logger.println("Uploading zip to s3://" + this.s3bucket + "/" + key);
298299
PutObjectResult s3result = aws.s3.putObject(this.s3bucket, key, zipFile);
299300

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
<div>
2-
The prefix in the S3 Bucket to prepend to the AWS CodeDeploy revision. Default is the root of the bucket.
2+
The prefix in the S3 Bucket to prepend to the AWS CodeDeploy revision. Default is the root of the bucket. You can
3+
use environment variables in this field.
34
</div>

0 commit comments

Comments
 (0)