3434import hudson .FilePath ;
3535import hudson .Launcher ;
3636import hudson .Extension ;
37+ import hudson .Util ;
3738import hudson .model .AbstractBuild ;
3839import hudson .model .BuildListener ;
3940import hudson .model .AbstractProject ;
5859import java .io .IOException ;
5960import java .io .PrintStream ;
6061import java .util .Date ;
62+ import java .util .Map ;
6163import java .util .UUID ;
6264
6365import 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
0 commit comments