Skip to content

Commit 073c800

Browse files
committed
Add environment variables to S3 prefix setting
1 parent 09f223e commit 073c800

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

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

Lines changed: 6 additions & 4 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;
@@ -165,7 +167,7 @@ public AWSCodeDeployPublisher(
165167
}
166168

167169
@Override
168-
public boolean perform(AbstractBuild build, Launcher launcher, BuildListener listener) {
170+
public boolean perform(AbstractBuild build, Launcher launcher, BuildListener listener) throws IOException, InterruptedException {
169171

170172
this.logger = listener.getLogger();
171173
final boolean buildFailed = build.getResult() == Result.FAILURE;
@@ -205,7 +207,7 @@ public boolean perform(AbstractBuild build, Launcher launcher, BuildListener lis
205207
verifyCodeDeployApplication(aws);
206208

207209
String projectName = build.getProject().getName();
208-
RevisionLocation revisionLocation = zipAndUpload(aws, projectName, build.getWorkspace());
210+
RevisionLocation revisionLocation = zipAndUpload(aws, projectName, build.getWorkspace(), build.getEnvironment(listener));
209211

210212
registerRevision(aws, revisionLocation);
211213
String deploymentId = createDeployment(aws, revisionLocation);
@@ -243,7 +245,7 @@ private void verifyCodeDeployApplication(AWSClients aws) throws IllegalArgumentE
243245
}
244246
}
245247

246-
private RevisionLocation zipAndUpload(AWSClients aws, String projectName, FilePath workspace) throws IOException, InterruptedException {
248+
private RevisionLocation zipAndUpload(AWSClients aws, String projectName, FilePath workspace, Map<String, String> envVars) throws IOException, InterruptedException {
247249

248250
File zipFile = File.createTempFile(projectName + "-", ".zip");
249251
this.logger.println("Zipping workspace into " + zipFile.getAbsolutePath());
@@ -257,7 +259,7 @@ private RevisionLocation zipAndUpload(AWSClients aws, String projectName, FilePa
257259
if (this.s3prefix.isEmpty()) {
258260
key = zipFile.getName();
259261
} else {
260-
key = this.s3prefix;
262+
key = Util.replaceMacro(this.s3prefix, envVars);
261263
if (this.s3prefix.endsWith("/")) {
262264
key += zipFile.getName();
263265
} else {
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)