From 1312c91e886e1d4bbaeb1321c0473f9ee079ea54 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Sat, 13 May 2017 17:32:08 +0000 Subject: [PATCH 1/3] sync from repo https://github.com/jenkinsci/aws-codedeploy-plugin.git and fix the issue of failed deployment for awslab --- appspec.yml | 18 +++++ pom.xml | 18 ++--- pom.xml.awslab.backup | 77 +++++++++++++++++++ scripts/install_dependencies | 3 + scripts/start_server | 3 + scripts/stop_server | 6 ++ .../com/amazonaws/codedeploy/AWSClients.java | 3 +- .../codedeploy/AWSCodeDeployPublisher.java | 47 +++++++---- .../AWSCodeDeployPublisher/config.jelly | 1 + .../AWSCodeDeployPublisher/global.jelly | 1 + src/main/resources/index.jelly | 1 + 11 files changed, 151 insertions(+), 27 deletions(-) create mode 100755 appspec.yml create mode 100644 pom.xml.awslab.backup create mode 100755 scripts/install_dependencies create mode 100755 scripts/start_server create mode 100755 scripts/stop_server diff --git a/appspec.yml b/appspec.yml new file mode 100755 index 0000000..7f0cdf9 --- /dev/null +++ b/appspec.yml @@ -0,0 +1,18 @@ +version: 0.0 +os: linux +files: + - source: /index.html + destination: /var/www/html/ +hooks: + BeforeInstall: + - location: scripts/install_dependencies + timeout: 300 + runas: root + - location: scripts/start_server + timeout: 300 + runas: root + ApplicationStop: + - location: scripts/stop_server + timeout: 300 + runas: root + diff --git a/pom.xml b/pom.xml index 834689c..6234a67 100644 --- a/pom.xml +++ b/pom.xml @@ -3,11 +3,11 @@ org.jenkins-ci.plugins plugin - 1.554.1 + 2.19 codedeploy - 1.12-SNAPSHOT + 1.17-SNAPSHOT hpi com.amazonaws AWS CodeDeploy Plugin for Jenkins @@ -16,9 +16,9 @@ - afitzgibbon - Andrew Fitz Gibbon - gibbon@amazon.com + jmcfar + Josh Mcfarlane + jmcfar@amazon.com @@ -45,16 +45,16 @@ - 2.1.1 - 3.0.7.RELEASE UTF-8 + 1.612 + 7 org.jenkins-ci.plugins aws-java-sdk - 1.10.26 + 1.11.119 @@ -69,9 +69,7 @@ maven-release-plugin - 2.5 - diff --git a/pom.xml.awslab.backup b/pom.xml.awslab.backup new file mode 100644 index 0000000..834689c --- /dev/null +++ b/pom.xml.awslab.backup @@ -0,0 +1,77 @@ + + 4.0.0 + + org.jenkins-ci.plugins + plugin + 1.554.1 + + + codedeploy + 1.12-SNAPSHOT + hpi + com.amazonaws + AWS CodeDeploy Plugin for Jenkins + Adds a post-build step to integrate Jenkins with AWS CodeDeploy + https://wiki.jenkins-ci.org/display/JENKINS/AWS+Codedeploy+plugin + + + + afitzgibbon + Andrew Fitz Gibbon + gibbon@amazon.com + + + + + + Apache License, Version 2.0 + http://www.apache.org/licenses/LICENSE-2.0.txt + repo + + + + + scm:git:ssh://github.com/jenkinsci/aws-codedeploy-plugin.git + scm:git:ssh://git@github.com/jenkinsci/aws-codedeploy-plugin.git + https://github.com/jenkinsci/aws-codedeploy-plugin + HEAD + + + + + repo.jenkins-ci.org + http://repo.jenkins-ci.org/public/ + + + + + 2.1.1 + 3.0.7.RELEASE + UTF-8 + + + + + org.jenkins-ci.plugins + aws-java-sdk + 1.10.26 + + + + + + repo.jenkins-ci.org + http://repo.jenkins-ci.org/public/ + + + + + + + maven-release-plugin + 2.5 + + + + + diff --git a/scripts/install_dependencies b/scripts/install_dependencies new file mode 100755 index 0000000..3d37299 --- /dev/null +++ b/scripts/install_dependencies @@ -0,0 +1,3 @@ +#!/bin/bash +yum install -y httpd + diff --git a/scripts/start_server b/scripts/start_server new file mode 100755 index 0000000..203194f --- /dev/null +++ b/scripts/start_server @@ -0,0 +1,3 @@ +#!/bin/bash +service httpd start + diff --git a/scripts/stop_server b/scripts/stop_server new file mode 100755 index 0000000..aef258b --- /dev/null +++ b/scripts/stop_server @@ -0,0 +1,6 @@ +#!/bin/bash +isExistApp=`pgrep httpd` +if [[ -n $isExistApp ]]; then + service httpd stop +fi + diff --git a/src/main/java/com/amazonaws/codedeploy/AWSClients.java b/src/main/java/com/amazonaws/codedeploy/AWSClients.java index 0826f20..376c3c1 100644 --- a/src/main/java/com/amazonaws/codedeploy/AWSClients.java +++ b/src/main/java/com/amazonaws/codedeploy/AWSClients.java @@ -72,6 +72,7 @@ public AWSClients(String region, AWSCredentials credentials, String proxyHost, i this.s3 = credentials != null ? new AmazonS3Client(credentials, clientCfg) : new AmazonS3Client(clientCfg); this.codedeploy = credentials != null ? new AmazonCodeDeployClient(credentials, clientCfg) : new AmazonCodeDeployClient(clientCfg); codedeploy.setRegion(Region.getRegion(Regions.fromName(this.region))); + s3.setRegion(Region.getRegion(Regions.fromName(this.region))); } public static AWSClients fromDefaultCredentialChain(String region, String proxyHost, int proxyPort) { @@ -129,7 +130,7 @@ private File createTestFile() throws IOException { File file = File.createTempFile("codedeploy-jenkins-plugin", ".txt"); file.deleteOnExit(); - Writer writer = new OutputStreamWriter(new FileOutputStream(file)); + Writer writer = new OutputStreamWriter(new FileOutputStream(file), "UTF-8"); writer.write(""); writer.close(); diff --git a/src/main/java/com/amazonaws/codedeploy/AWSCodeDeployPublisher.java b/src/main/java/com/amazonaws/codedeploy/AWSCodeDeployPublisher.java index e560eac..7ecc46f 100644 --- a/src/main/java/com/amazonaws/codedeploy/AWSCodeDeployPublisher.java +++ b/src/main/java/com/amazonaws/codedeploy/AWSCodeDeployPublisher.java @@ -56,8 +56,9 @@ import org.kohsuke.stapler.StaplerRequest; import java.io.File; +import java.io.FileInputStream; import java.io.FileOutputStream; -import java.io.FileReader; +import java.io.InputStreamReader; import java.io.IOException; import java.io.PrintStream; import java.util.Date; @@ -78,7 +79,7 @@ public class AWSCodeDeployPublisher extends Publisher { public static final long DEFAULT_TIMEOUT_SECONDS = 900; public static final long DEFAULT_POLLING_FREQUENCY_SECONDS = 15; public static final String ROLE_SESSION_NAME = "jenkins-codedeploy-plugin"; - public static final Regions[] AVAILABLE_REGIONS = {Regions.AP_NORTHEAST_1, Regions.AP_SOUTHEAST_1, Regions.AP_SOUTHEAST_2, Regions.EU_WEST_1, Regions.US_EAST_1, Regions.US_WEST_2, Regions.EU_CENTRAL_1, Regions.US_WEST_1, Regions.SA_EAST_1}; + private static final Regions[] AVAILABLE_REGIONS = {Regions.AP_NORTHEAST_1, Regions.AP_SOUTHEAST_1, Regions.AP_SOUTHEAST_2, Regions.EU_WEST_1, Regions.US_EAST_1, Regions.US_WEST_2, Regions.EU_CENTRAL_1, Regions.US_WEST_1, Regions.SA_EAST_1, Regions.AP_NORTHEAST_2, Regions.AP_SOUTH_1, Regions.US_EAST_2, Regions.CA_CENTRAL_1, Regions.EU_WEST_2, Regions.CN_NORTH_1}; private final String s3bucket; private final String s3prefix; @@ -190,7 +191,7 @@ public boolean perform(AbstractBuild build, Launcher launcher, BuildListener lis return true; } - AWSClients aws; + final AWSClients aws; if ("awsAccessKey".equals(credentials)) { if (StringUtils.isEmpty(this.awsAccessKey) && StringUtils.isEmpty(this.awsSecretKey)) { aws = AWSClients.fromDefaultCredentialChain( @@ -220,8 +221,13 @@ public boolean perform(AbstractBuild build, Launcher launcher, BuildListener lis verifyCodeDeployApplication(aws); - String projectName = build.getProject().getName(); - RevisionLocation revisionLocation = zipAndUpload(aws, projectName, getSourceDirectory(build.getWorkspace())); + final String projectName = build.getProject().getName(); + final FilePath workspace = build.getWorkspace(); + if (workspace == null) { + throw new IllegalArgumentException("No workspace present for the build."); + } + final FilePath sourceDirectory = getSourceDirectory(workspace); + final RevisionLocation revisionLocation = zipAndUpload(aws, projectName, sourceDirectory); registerRevision(aws, revisionLocation); if ("onlyRevision".equals(deploymentMethod)){ @@ -296,10 +302,10 @@ private RevisionLocation zipAndUpload(AWSClients aws, String projectName, FilePa File versionFile; versionFile = new File(sourceDirectory + "/" + versionFileName); - FileReader reader = null; + InputStreamReader reader = null; String version = null; try { - reader = new FileReader(versionFile); + reader = new InputStreamReader(new FileInputStream(versionFile), "UTF-8"); char[] chars = new char[(int) versionFile.length() -1]; reader.read(chars); version = new String(chars); @@ -312,7 +318,10 @@ private RevisionLocation zipAndUpload(AWSClients aws, String projectName, FilePa if (version != null){ zipFile = new File("/tmp/" + projectName + "-" + version + ".zip"); - zipFile.createNewFile(); + final boolean fileCreated = zipFile.createNewFile(); + if (!fileCreated) { + logger.println("File already exists, overwriting: " + zipFile.getPath()); + } } else { zipFile = File.createTempFile(projectName + "-", ".zip"); } @@ -344,12 +353,15 @@ private RevisionLocation zipAndUpload(AWSClients aws, String projectName, FilePa logger.println("Zipping files into " + zipFile.getAbsolutePath()); - - - sourceDirectory.zip( - new FileOutputStream(zipFile), - new DirScanner.Glob(this.includes, this.excludes) - ); + FileOutputStream outputStream = new FileOutputStream(zipFile); + try { + sourceDirectory.zip( + outputStream, + new DirScanner.Glob(this.includes, this.excludes) + ); + } finally { + outputStream.close(); + } if (prefix.isEmpty()) { key = zipFile.getName(); @@ -376,7 +388,10 @@ private RevisionLocation zipAndUpload(AWSClients aws, String projectName, FilePa return revisionLocation; } finally { - zipFile.delete(); + final boolean deleted = zipFile.delete(); + if (!deleted) { + logger.println("Failed to clean up file " + zipFile.getPath()); + } } } @@ -531,7 +546,7 @@ public boolean configure(StaplerRequest req, JSONObject formData) throws FormExc awsAccessKey = formData.getString("awsAccessKey"); awsSecretKey = formData.getString("awsSecretKey"); proxyHost = formData.getString("proxyHost"); - proxyPort = Integer.valueOf(formData.getString("proxyPort")); + proxyPort = Integer.parseInt(formData.getString("proxyPort")); req.bindJSON(this, formData); save(); diff --git a/src/main/resources/com/amazonaws/codedeploy/AWSCodeDeployPublisher/config.jelly b/src/main/resources/com/amazonaws/codedeploy/AWSCodeDeployPublisher/config.jelly index 91b48e1..104cdb1 100644 --- a/src/main/resources/com/amazonaws/codedeploy/AWSCodeDeployPublisher/config.jelly +++ b/src/main/resources/com/amazonaws/codedeploy/AWSCodeDeployPublisher/config.jelly @@ -1,3 +1,4 @@ + diff --git a/src/main/resources/com/amazonaws/codedeploy/AWSCodeDeployPublisher/global.jelly b/src/main/resources/com/amazonaws/codedeploy/AWSCodeDeployPublisher/global.jelly index af90a41..1c2c857 100644 --- a/src/main/resources/com/amazonaws/codedeploy/AWSCodeDeployPublisher/global.jelly +++ b/src/main/resources/com/amazonaws/codedeploy/AWSCodeDeployPublisher/global.jelly @@ -1,3 +1,4 @@ + diff --git a/src/main/resources/index.jelly b/src/main/resources/index.jelly index fb6d97d..51d3140 100644 --- a/src/main/resources/index.jelly +++ b/src/main/resources/index.jelly @@ -1,3 +1,4 @@ +
This plugin provides a "post-build" step for AWS CodeDeploy.
From de6b82c1ae9545be6809fc7144900353f5026aa0 Mon Sep 17 00:00:00 2001 From: Josh McFarlane Date: Mon, 18 Dec 2017 19:58:34 +0000 Subject: [PATCH 2/3] Update plugin to allow concurrent build executions. --- pom.xml.awslab.backup | 77 ------------------- .../com/amazonaws/codedeploy/AWSClients.java | 2 + .../codedeploy/AWSCodeDeployPublisher.java | 8 +- 3 files changed, 5 insertions(+), 82 deletions(-) delete mode 100644 pom.xml.awslab.backup diff --git a/pom.xml.awslab.backup b/pom.xml.awslab.backup deleted file mode 100644 index 834689c..0000000 --- a/pom.xml.awslab.backup +++ /dev/null @@ -1,77 +0,0 @@ - - 4.0.0 - - org.jenkins-ci.plugins - plugin - 1.554.1 - - - codedeploy - 1.12-SNAPSHOT - hpi - com.amazonaws - AWS CodeDeploy Plugin for Jenkins - Adds a post-build step to integrate Jenkins with AWS CodeDeploy - https://wiki.jenkins-ci.org/display/JENKINS/AWS+Codedeploy+plugin - - - - afitzgibbon - Andrew Fitz Gibbon - gibbon@amazon.com - - - - - - Apache License, Version 2.0 - http://www.apache.org/licenses/LICENSE-2.0.txt - repo - - - - - scm:git:ssh://github.com/jenkinsci/aws-codedeploy-plugin.git - scm:git:ssh://git@github.com/jenkinsci/aws-codedeploy-plugin.git - https://github.com/jenkinsci/aws-codedeploy-plugin - HEAD - - - - - repo.jenkins-ci.org - http://repo.jenkins-ci.org/public/ - - - - - 2.1.1 - 3.0.7.RELEASE - UTF-8 - - - - - org.jenkins-ci.plugins - aws-java-sdk - 1.10.26 - - - - - - repo.jenkins-ci.org - http://repo.jenkins-ci.org/public/ - - - - - - - maven-release-plugin - 2.5 - - - - - diff --git a/src/main/java/com/amazonaws/codedeploy/AWSClients.java b/src/main/java/com/amazonaws/codedeploy/AWSClients.java index 376c3c1..d7fb709 100644 --- a/src/main/java/com/amazonaws/codedeploy/AWSClients.java +++ b/src/main/java/com/amazonaws/codedeploy/AWSClients.java @@ -90,6 +90,8 @@ public static AWSClients fromBasicCredentials(String region, String awsAccessKey /** * Via the default provider chain (i.e., global keys for this Jenkins instance), return the account ID for the * currently authenticated user. + * @param proxyHost hostname of the proxy to use (if any) + * @param proxyPort port of the proxy to use (if any) * @return 12-digit account id */ public static String getAccountId(String proxyHost, int proxyPort) { diff --git a/src/main/java/com/amazonaws/codedeploy/AWSCodeDeployPublisher.java b/src/main/java/com/amazonaws/codedeploy/AWSCodeDeployPublisher.java index 7ecc46f..a164b92 100644 --- a/src/main/java/com/amazonaws/codedeploy/AWSCodeDeployPublisher.java +++ b/src/main/java/com/amazonaws/codedeploy/AWSCodeDeployPublisher.java @@ -70,7 +70,7 @@ /** * The AWS CodeDeploy Publisher is a post-build plugin that adds the ability to start a new CodeDeploy deployment * with the project's workspace as the application revision. - *

+ * * To configure, users must create an IAM role that allows "S3" and "CodeDeploy" actions and must be assumable by * the globally configured keys. This allows the plugin to get temporary credentials instead of requiring permanent * credentials to be configured for each project. @@ -488,15 +488,13 @@ public DescriptorImpl getDescriptor() { } public BuildStepMonitor getRequiredMonitorService() { - - return BuildStepMonitor.STEP; + return BuildStepMonitor.NONE; } /** * Descriptor for {@link AWSCodeDeployPublisher}. Used as a singleton. * The class is marked as public so that it can be accessed from views. - *

- *

+ * * See src/main/resources/com/amazonaws/codedeploy/AWSCodeDeployPublisher/*.jelly * for the actual HTML fragment for the configuration screen. */ From 7f85b36142327594eee7da23ef4c1a200a0001a9 Mon Sep 17 00:00:00 2001 From: Josh McFarlane Date: Mon, 18 Dec 2017 22:55:16 +0000 Subject: [PATCH 3/3] Removing sample application files that should not be present in plugin. --- appspec.yml | 18 ------------------ scripts/install_dependencies | 3 --- scripts/start_server | 3 --- scripts/stop_server | 6 ------ 4 files changed, 30 deletions(-) delete mode 100755 appspec.yml delete mode 100755 scripts/install_dependencies delete mode 100755 scripts/start_server delete mode 100755 scripts/stop_server diff --git a/appspec.yml b/appspec.yml deleted file mode 100755 index 7f0cdf9..0000000 --- a/appspec.yml +++ /dev/null @@ -1,18 +0,0 @@ -version: 0.0 -os: linux -files: - - source: /index.html - destination: /var/www/html/ -hooks: - BeforeInstall: - - location: scripts/install_dependencies - timeout: 300 - runas: root - - location: scripts/start_server - timeout: 300 - runas: root - ApplicationStop: - - location: scripts/stop_server - timeout: 300 - runas: root - diff --git a/scripts/install_dependencies b/scripts/install_dependencies deleted file mode 100755 index 3d37299..0000000 --- a/scripts/install_dependencies +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash -yum install -y httpd - diff --git a/scripts/start_server b/scripts/start_server deleted file mode 100755 index 203194f..0000000 --- a/scripts/start_server +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash -service httpd start - diff --git a/scripts/stop_server b/scripts/stop_server deleted file mode 100755 index aef258b..0000000 --- a/scripts/stop_server +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash -isExistApp=`pgrep httpd` -if [[ -n $isExistApp ]]; then - service httpd stop -fi -