5757
5858import java .io .File ;
5959import java .io .FileOutputStream ;
60+ import java .io .FileReader ;
6061import java .io .IOException ;
6162import java .io .PrintStream ;
6263import java .util .Date ;
@@ -101,6 +102,7 @@ public class AWSCodeDeployPublisher extends Publisher {
101102 private final String awsSecretKey ;
102103 private final String credentials ;
103104 private final String deploymentMethod ;
105+ private final String versionFileName ;
104106
105107 private PrintStream logger ;
106108 private Map <String , String > envVars ;
@@ -118,6 +120,7 @@ public AWSCodeDeployPublisher(
118120 Long pollingTimeoutSec ,
119121 Long pollingFreqSec ,
120122 String credentials ,
123+ String versionFileName ,
121124 String deploymentMethod ,
122125 String awsAccessKey ,
123126 String awsSecretKey ,
@@ -145,6 +148,7 @@ public AWSCodeDeployPublisher(
145148 this .proxyPort = proxyPort ;
146149 this .credentials = credentials ;
147150 this .deploymentMethod = deploymentMethod ;
151+ this .versionFileName = versionFileName ;
148152 this .awsAccessKey = awsAccessKey ;
149153 this .awsSecretKey = awsSecretKey ;
150154 this .iamRoleArn = iamRoleArn ;
@@ -336,13 +340,35 @@ private RevisionLocation zipAndUpload(AWSClients aws, String projectName, FilePa
336340 logger .println ("Uploading zip to s3://" + bucket + "/" + key );
337341 PutObjectResult s3result = aws .s3 .putObject (bucket , key , zipFile );
338342
343+ File versionFile ;
344+ versionFile = new File (sourceDirectory + "/" + versionFileName );
345+
346+ FileReader reader = null ;
347+ String version = null ;
348+ try {
349+ reader = new FileReader (versionFile );
350+ char [] chars = new char [(int ) versionFile .length ()];
351+ reader .read (chars );
352+ version = new String (chars );
353+ reader .close ();
354+ } catch (IOException e ) {
355+ e .printStackTrace ();
356+ } finally {
357+ if (reader !=null ){reader .close ();}
358+ }
339359
340360 S3Location s3Location = new S3Location ();
341361 s3Location .setBucket (bucket );
342362 s3Location .setKey (key );
343363 s3Location .setBundleType (BundleType .Zip );
344364 s3Location .setETag (s3result .getETag ());
345365
366+ if (version != null ){
367+ s3Location .setVersion (version );
368+ }
369+
370+
371+
346372 RevisionLocation revisionLocation = new RevisionLocation ();
347373 revisionLocation .setRevisionType (RevisionLocationType .S3 );
348374 revisionLocation .setS3Location (s3Location );
@@ -645,6 +671,10 @@ public String getDeploymentMethod() {
645671 return deploymentMethod ;
646672 }
647673
674+ public String getVersionFileName () {
675+ return versionFileName ;
676+ }
677+
648678 public boolean getWaitForCompletion () {
649679 return waitForCompletion ;
650680 }
0 commit comments