From 250ef6b868c64ead2aa85e659eda426af1e33faa Mon Sep 17 00:00:00 2001 From: Thomas Colin de Verdiere Date: Fri, 14 Sep 2018 17:27:11 +0200 Subject: [PATCH 1/3] Add zip name prefix + correct tmp dir for windows --- .../codedeploy/AWSCodeDeployPublisher.java | 22 +++++++++++++++++-- .../AWSCodeDeployPublisher/config.jelly | 3 +++ .../help-versionFileName.html | 11 ++++++++++ .../help-zipNamePrefix.html | 4 ++++ 4 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 src/main/resources/com/amazonaws/codedeploy/AWSCodeDeployPublisher/help-versionFileName.html create mode 100644 src/main/resources/com/amazonaws/codedeploy/AWSCodeDeployPublisher/help-zipNamePrefix.html diff --git a/src/main/java/com/amazonaws/codedeploy/AWSCodeDeployPublisher.java b/src/main/java/com/amazonaws/codedeploy/AWSCodeDeployPublisher.java index e39fe9e..5f7b77d 100644 --- a/src/main/java/com/amazonaws/codedeploy/AWSCodeDeployPublisher.java +++ b/src/main/java/com/amazonaws/codedeploy/AWSCodeDeployPublisher.java @@ -107,6 +107,7 @@ public class AWSCodeDeployPublisher extends Publisher implements SimpleBuildStep private final String awsSecretKey; private final String credentials; private final String deploymentMethod; + private final String zipNamePrefix; private final String versionFileName; private PrintStream logger; @@ -127,6 +128,7 @@ public AWSCodeDeployPublisher( Long pollingTimeoutSec, Long pollingFreqSec, String credentials, + String zipNamePrefix, String versionFileName, String deploymentMethod, String awsAccessKey, @@ -155,6 +157,7 @@ public AWSCodeDeployPublisher( this.proxyPort = proxyPort; this.credentials = credentials; this.deploymentMethod = deploymentMethod; + this.zipNamePrefix = zipNamePrefix; this.versionFileName = versionFileName; this.awsAccessKey = awsAccessKey; this.awsSecretKey = awsSecretKey; @@ -230,7 +233,14 @@ public void perform(@Nonnull Run build, @Nonnull FilePath workspace, @Nonnu verifyCodeDeployApplication(aws); - final String projectName = build.getDisplayName(); + String projectName = null; + logger.println("Zip name prefix: " + this.zipNamePrefix ); + if (this.zipNamePrefix != null && this.zipNamePrefix.trim().length() > 0) { + projectName = build.getEnvironment(listener).expand(zipNamePrefix.trim()); + } else { + projectName = build.getDisplayName(); + } + if (workspace == null) { throw new IllegalArgumentException("No workspace present for the build."); } @@ -317,6 +327,8 @@ private RevisionLocation zipAndUpload(AWSClients aws, String projectName, FilePa File versionFile; versionFile = new File(sourceDirectory + "/" + versionFileName); + logger.println("Project name: " + projectName + " - Version file path : " + versionFile.getAbsolutePath() + " - Version filename : " + versionFileName); + InputStreamReader reader = null; String version = null; try { @@ -332,7 +344,9 @@ private RevisionLocation zipAndUpload(AWSClients aws, String projectName, FilePa } if (version != null){ - zipFile = new File("/tmp/" + projectName + "-" + version + ".zip"); + String tempDir = System.getProperty("java.io.tmpdir"); + + zipFile = new File(tempDir + File.separator + projectName + "-" + version + ".zip"); final boolean fileCreated = zipFile.createNewFile(); if (!fileCreated) { logger.println("File already exists, overwriting: " + zipFile.getPath()); @@ -713,6 +727,10 @@ public String getDeploymentMethod() { return deploymentMethod; } + public String getZipNamePrefix() { + return zipNamePrefix; + } + public String getVersionFileName() { return versionFileName; } diff --git a/src/main/resources/com/amazonaws/codedeploy/AWSCodeDeployPublisher/config.jelly b/src/main/resources/com/amazonaws/codedeploy/AWSCodeDeployPublisher/config.jelly index d3ba81d..a1d1b62 100644 --- a/src/main/resources/com/amazonaws/codedeploy/AWSCodeDeployPublisher/config.jelly +++ b/src/main/resources/com/amazonaws/codedeploy/AWSCodeDeployPublisher/config.jelly @@ -39,6 +39,9 @@ + + + diff --git a/src/main/resources/com/amazonaws/codedeploy/AWSCodeDeployPublisher/help-versionFileName.html b/src/main/resources/com/amazonaws/codedeploy/AWSCodeDeployPublisher/help-versionFileName.html new file mode 100644 index 0000000..07b13f2 --- /dev/null +++ b/src/main/resources/com/amazonaws/codedeploy/AWSCodeDeployPublisher/help-versionFileName.html @@ -0,0 +1,11 @@ +
+ The path to a version file name relative to the subdirectory. The file must contain a version of the application. + If Version file name is set the name of the zip uploaded to S3 will be : + build display name + "-" + version.zip + Or + Zip prefix name + "-" + version.zip + If not set, the name will be + build display name + "-" + generated uid.zip + Or + Zip prefix name + "-" + generated uid.zip +
diff --git a/src/main/resources/com/amazonaws/codedeploy/AWSCodeDeployPublisher/help-zipNamePrefix.html b/src/main/resources/com/amazonaws/codedeploy/AWSCodeDeployPublisher/help-zipNamePrefix.html new file mode 100644 index 0000000..06a65d2 --- /dev/null +++ b/src/main/resources/com/amazonaws/codedeploy/AWSCodeDeployPublisher/help-zipNamePrefix.html @@ -0,0 +1,4 @@ +
+ The prefix of the name of the zip you wish to deploy to S3. If none is set it will use the display name of the build. + This is usually the build number. Ex: #3 +
From c04883031e2c9afe55baefbb8c0e4bea509b0542 Mon Sep 17 00:00:00 2001 From: Thomas Colin de Verdiere Date: Fri, 14 Sep 2018 17:33:34 +0200 Subject: [PATCH 2/3] Correct parameter case and documentation --- .../amazonaws/codedeploy/AWSCodeDeployPublisher/config.jelly | 2 +- .../codedeploy/AWSCodeDeployPublisher/help-zipNamePrefix.html | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/resources/com/amazonaws/codedeploy/AWSCodeDeployPublisher/config.jelly b/src/main/resources/com/amazonaws/codedeploy/AWSCodeDeployPublisher/config.jelly index a1d1b62..2b5fe3a 100644 --- a/src/main/resources/com/amazonaws/codedeploy/AWSCodeDeployPublisher/config.jelly +++ b/src/main/resources/com/amazonaws/codedeploy/AWSCodeDeployPublisher/config.jelly @@ -39,7 +39,7 @@ - + diff --git a/src/main/resources/com/amazonaws/codedeploy/AWSCodeDeployPublisher/help-zipNamePrefix.html b/src/main/resources/com/amazonaws/codedeploy/AWSCodeDeployPublisher/help-zipNamePrefix.html index 06a65d2..cc7ce94 100644 --- a/src/main/resources/com/amazonaws/codedeploy/AWSCodeDeployPublisher/help-zipNamePrefix.html +++ b/src/main/resources/com/amazonaws/codedeploy/AWSCodeDeployPublisher/help-zipNamePrefix.html @@ -1,4 +1,3 @@
- The prefix of the name of the zip you wish to deploy to S3. If none is set it will use the display name of the build. - This is usually the build number. Ex: #3 + The prefix of the name of the zip you wish to deploy to S3. If none is set it will use the display name of the build (ex: #3).
From 1716badc256331b2c487bfcc67221c532756eafb Mon Sep 17 00:00:00 2001 From: Thomas Colin de Verdiere Date: Fri, 14 Sep 2018 17:40:26 +0200 Subject: [PATCH 3/3] Change documentation of Zip Name Prefix --- .../codedeploy/AWSCodeDeployPublisher/help-zipNamePrefix.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/com/amazonaws/codedeploy/AWSCodeDeployPublisher/help-zipNamePrefix.html b/src/main/resources/com/amazonaws/codedeploy/AWSCodeDeployPublisher/help-zipNamePrefix.html index cc7ce94..909dc72 100644 --- a/src/main/resources/com/amazonaws/codedeploy/AWSCodeDeployPublisher/help-zipNamePrefix.html +++ b/src/main/resources/com/amazonaws/codedeploy/AWSCodeDeployPublisher/help-zipNamePrefix.html @@ -1,3 +1,3 @@
- The prefix of the name of the zip you wish to deploy to S3. If none is set it will use the display name of the build (ex: #3). + The prefix of the name of the zip you wish to deploy to S3. If none is set the display name of the build (ex: #3) will be use.