Skip to content

Commit 26bc6a1

Browse files
author
Wagner Spirigoni
committed
Changing name of the file to use a version from a text file, helping to identificate which file is the one to deploy or rollback to.
1 parent a9d330e commit 26bc6a1

File tree

1 file changed

+25
-24
lines changed

1 file changed

+25
-24
lines changed

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

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,31 @@ private void verifyCodeDeployApplication(AWSClients aws) throws IllegalArgumentE
292292

293293
private RevisionLocation zipAndUpload(AWSClients aws, String projectName, FilePath sourceDirectory) throws IOException, InterruptedException, IllegalArgumentException {
294294

295-
File zipFile = File.createTempFile(projectName + "-", ".zip");
295+
File zipFile = null;
296+
File versionFile;
297+
versionFile = new File(sourceDirectory + "/" + versionFileName);
298+
299+
FileReader reader = null;
300+
String version = null;
301+
try {
302+
reader = new FileReader(versionFile);
303+
char[] chars = new char[(int) versionFile.length() -1];
304+
reader.read(chars);
305+
version = new String(chars);
306+
reader.close();
307+
} catch (IOException e) {
308+
e.printStackTrace();
309+
} finally {
310+
if(reader !=null){reader.close();}
311+
}
312+
313+
if (version != null){
314+
zipFile = new File("/tmp/" + projectName + "-" + version + ".zip");
315+
zipFile.createNewFile();
316+
} else {
317+
zipFile = File.createTempFile(projectName + "-", ".zip");
318+
}
319+
296320
String key;
297321
File appspec;
298322
File dest;
@@ -340,35 +364,12 @@ private RevisionLocation zipAndUpload(AWSClients aws, String projectName, FilePa
340364
logger.println("Uploading zip to s3://" + bucket + "/" + key);
341365
PutObjectResult s3result = aws.s3.putObject(bucket, key, zipFile);
342366

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-
}
359-
360367
S3Location s3Location = new S3Location();
361368
s3Location.setBucket(bucket);
362369
s3Location.setKey(key);
363370
s3Location.setBundleType(BundleType.Zip);
364371
s3Location.setETag(s3result.getETag());
365372

366-
if (version != null){
367-
s3Location.setVersion(version);
368-
}
369-
370-
371-
372373
RevisionLocation revisionLocation = new RevisionLocation();
373374
revisionLocation.setRevisionType(RevisionLocationType.S3);
374375
revisionLocation.setS3Location(s3Location);

0 commit comments

Comments
 (0)