diff --git a/src/main/java/com/amazonaws/codedeploy/AWSCodeDeployPublisher.java b/src/main/java/com/amazonaws/codedeploy/AWSCodeDeployPublisher.java index 931dcc3..c45089d 100644 --- a/src/main/java/com/amazonaws/codedeploy/AWSCodeDeployPublisher.java +++ b/src/main/java/com/amazonaws/codedeploy/AWSCodeDeployPublisher.java @@ -244,42 +244,47 @@ private void verifyCodeDeployApplication(AWSClients aws) throws IllegalArgumentE } private RevisionLocation zipAndUpload(AWSClients aws, String projectName, FilePath workspace) throws IOException, InterruptedException { - + File zipFile = File.createTempFile(projectName + "-", ".zip"); - this.logger.println("Zipping workspace into " + zipFile.getAbsolutePath()); + String key; + + try { - workspace.zip( - new FileOutputStream(zipFile), - new DirScanner.Glob(this.includes, this.excludes) - ); + this.logger.println("Zipping workspace into " + zipFile.getAbsolutePath()); + workspace.zip( + new FileOutputStream(zipFile), + new DirScanner.Glob(this.includes, this.excludes) + ); - String key; - if (this.s3prefix.isEmpty()) { - key = zipFile.getName(); - } else { - key = this.s3prefix; - if (this.s3prefix.endsWith("/")) { - key += zipFile.getName(); + if (this.s3prefix.isEmpty()) { + key = zipFile.getName(); } else { - key += "/" + zipFile.getName(); + key = this.s3prefix; + if (this.s3prefix.endsWith("/")) { + key += zipFile.getName(); + } else { + key += "/" + zipFile.getName(); + } } - } - logger.println("Uploading zip to s3://" + this.s3bucket + "/" + key); - PutObjectResult s3result = aws.s3.putObject(this.s3bucket, key, zipFile); + logger.println("Uploading zip to s3://" + this.s3bucket + "/" + key); + PutObjectResult s3result = aws.s3.putObject(this.s3bucket, key, zipFile); - S3Location s3Location = new S3Location(); - s3Location.setBucket(this.s3bucket); - s3Location.setKey(key); - s3Location.setBundleType(BundleType.Zip); - s3Location.setETag(s3result.getETag()); + S3Location s3Location = new S3Location(); + s3Location.setBucket(this.s3bucket); + s3Location.setKey(key); + s3Location.setBundleType(BundleType.Zip); + s3Location.setETag(s3result.getETag()); - RevisionLocation revisionLocation = new RevisionLocation(); - revisionLocation.setRevisionType(RevisionLocationType.S3); - revisionLocation.setS3Location(s3Location); + RevisionLocation revisionLocation = new RevisionLocation(); + revisionLocation.setRevisionType(RevisionLocationType.S3); + revisionLocation.setS3Location(s3Location); - return revisionLocation; + return revisionLocation; + } finally { + zipFile.delete(); + } } private void registerRevision(AWSClients aws, RevisionLocation revisionLocation) {