Skip to content

Commit 1312c91

Browse files
author
Ubuntu
committed
sync from repo https://github.com/jenkinsci/aws-codedeploy-plugin.git and fix the issue of failed deployment for awslab
1 parent 5c9182f commit 1312c91

File tree

11 files changed

+151
-27
lines changed

11 files changed

+151
-27
lines changed

appspec.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
version: 0.0
2+
os: linux
3+
files:
4+
- source: /index.html
5+
destination: /var/www/html/
6+
hooks:
7+
BeforeInstall:
8+
- location: scripts/install_dependencies
9+
timeout: 300
10+
runas: root
11+
- location: scripts/start_server
12+
timeout: 300
13+
runas: root
14+
ApplicationStop:
15+
- location: scripts/stop_server
16+
timeout: 300
17+
runas: root
18+

pom.xml

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
<parent>
44
<groupId>org.jenkins-ci.plugins</groupId>
55
<artifactId>plugin</artifactId>
6-
<version>1.554.1</version>
6+
<version>2.19</version>
77
</parent>
88

99
<artifactId>codedeploy</artifactId>
10-
<version>1.12-SNAPSHOT</version>
10+
<version>1.17-SNAPSHOT</version>
1111
<packaging>hpi</packaging>
1212
<groupId>com.amazonaws</groupId>
1313
<name>AWS CodeDeploy Plugin for Jenkins</name>
@@ -16,9 +16,9 @@
1616

1717
<developers>
1818
<developer>
19-
<id>afitzgibbon</id>
20-
<name>Andrew Fitz Gibbon</name>
21-
<email>gibbon@amazon.com</email>
19+
<id>jmcfar</id>
20+
<name>Josh Mcfarlane</name>
21+
<email>jmcfar@amazon.com</email>
2222
</developer>
2323
</developers>
2424

@@ -45,16 +45,16 @@
4545
</repositories>
4646

4747
<properties>
48-
<jackson.version>2.1.1</jackson.version>
49-
<spring.version>3.0.7.RELEASE</spring.version>
5048
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
49+
<jenkins.version>1.612</jenkins.version>
50+
<java.level>7</java.level>
5151
</properties>
5252

5353
<dependencies>
5454
<dependency>
5555
<groupId>org.jenkins-ci.plugins</groupId>
5656
<artifactId>aws-java-sdk</artifactId>
57-
<version>1.10.26</version>
57+
<version>1.11.119</version>
5858
</dependency>
5959
</dependencies>
6060

@@ -69,9 +69,7 @@
6969
<plugins>
7070
<plugin>
7171
<artifactId>maven-release-plugin</artifactId>
72-
<version>2.5</version>
7372
</plugin>
7473
</plugins>
7574
</build>
76-
7775
</project>

pom.xml.awslab.backup

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
2+
<modelVersion>4.0.0</modelVersion>
3+
<parent>
4+
<groupId>org.jenkins-ci.plugins</groupId>
5+
<artifactId>plugin</artifactId>
6+
<version>1.554.1</version>
7+
</parent>
8+
9+
<artifactId>codedeploy</artifactId>
10+
<version>1.12-SNAPSHOT</version>
11+
<packaging>hpi</packaging>
12+
<groupId>com.amazonaws</groupId>
13+
<name>AWS CodeDeploy Plugin for Jenkins</name>
14+
<description>Adds a post-build step to integrate Jenkins with AWS CodeDeploy</description>
15+
<url>https://wiki.jenkins-ci.org/display/JENKINS/AWS+Codedeploy+plugin</url>
16+
17+
<developers>
18+
<developer>
19+
<id>afitzgibbon</id>
20+
<name>Andrew Fitz Gibbon</name>
21+
<email>gibbon@amazon.com</email>
22+
</developer>
23+
</developers>
24+
25+
<licenses>
26+
<license>
27+
<name>Apache License, Version 2.0</name>
28+
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
29+
<distribution>repo</distribution>
30+
</license>
31+
</licenses>
32+
33+
<scm>
34+
<connection>scm:git:ssh://github.com/jenkinsci/aws-codedeploy-plugin.git</connection>
35+
<developerConnection>scm:git:ssh://git@github.com/jenkinsci/aws-codedeploy-plugin.git</developerConnection>
36+
<url>https://github.com/jenkinsci/aws-codedeploy-plugin</url>
37+
<tag>HEAD</tag>
38+
</scm>
39+
40+
<repositories>
41+
<repository>
42+
<id>repo.jenkins-ci.org</id>
43+
<url>http://repo.jenkins-ci.org/public/</url>
44+
</repository>
45+
</repositories>
46+
47+
<properties>
48+
<jackson.version>2.1.1</jackson.version>
49+
<spring.version>3.0.7.RELEASE</spring.version>
50+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
51+
</properties>
52+
53+
<dependencies>
54+
<dependency>
55+
<groupId>org.jenkins-ci.plugins</groupId>
56+
<artifactId>aws-java-sdk</artifactId>
57+
<version>1.10.26</version>
58+
</dependency>
59+
</dependencies>
60+
61+
<pluginRepositories>
62+
<pluginRepository>
63+
<id>repo.jenkins-ci.org</id>
64+
<url>http://repo.jenkins-ci.org/public/</url>
65+
</pluginRepository>
66+
</pluginRepositories>
67+
68+
<build>
69+
<plugins>
70+
<plugin>
71+
<artifactId>maven-release-plugin</artifactId>
72+
<version>2.5</version>
73+
</plugin>
74+
</plugins>
75+
</build>
76+
77+
</project>

scripts/install_dependencies

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
yum install -y httpd
3+

scripts/start_server

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
service httpd start
3+

scripts/stop_server

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
isExistApp=`pgrep httpd`
3+
if [[ -n $isExistApp ]]; then
4+
service httpd stop
5+
fi
6+

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public AWSClients(String region, AWSCredentials credentials, String proxyHost, i
7272
this.s3 = credentials != null ? new AmazonS3Client(credentials, clientCfg) : new AmazonS3Client(clientCfg);
7373
this.codedeploy = credentials != null ? new AmazonCodeDeployClient(credentials, clientCfg) : new AmazonCodeDeployClient(clientCfg);
7474
codedeploy.setRegion(Region.getRegion(Regions.fromName(this.region)));
75+
s3.setRegion(Region.getRegion(Regions.fromName(this.region)));
7576
}
7677

7778
public static AWSClients fromDefaultCredentialChain(String region, String proxyHost, int proxyPort) {
@@ -129,7 +130,7 @@ private File createTestFile() throws IOException {
129130
File file = File.createTempFile("codedeploy-jenkins-plugin", ".txt");
130131
file.deleteOnExit();
131132

132-
Writer writer = new OutputStreamWriter(new FileOutputStream(file));
133+
Writer writer = new OutputStreamWriter(new FileOutputStream(file), "UTF-8");
133134
writer.write("");
134135
writer.close();
135136

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

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,9 @@
5656
import org.kohsuke.stapler.StaplerRequest;
5757

5858
import java.io.File;
59+
import java.io.FileInputStream;
5960
import java.io.FileOutputStream;
60-
import java.io.FileReader;
61+
import java.io.InputStreamReader;
6162
import java.io.IOException;
6263
import java.io.PrintStream;
6364
import java.util.Date;
@@ -78,7 +79,7 @@ public class AWSCodeDeployPublisher extends Publisher {
7879
public static final long DEFAULT_TIMEOUT_SECONDS = 900;
7980
public static final long DEFAULT_POLLING_FREQUENCY_SECONDS = 15;
8081
public static final String ROLE_SESSION_NAME = "jenkins-codedeploy-plugin";
81-
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};
82+
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};
8283

8384
private final String s3bucket;
8485
private final String s3prefix;
@@ -190,7 +191,7 @@ public boolean perform(AbstractBuild build, Launcher launcher, BuildListener lis
190191
return true;
191192
}
192193

193-
AWSClients aws;
194+
final AWSClients aws;
194195
if ("awsAccessKey".equals(credentials)) {
195196
if (StringUtils.isEmpty(this.awsAccessKey) && StringUtils.isEmpty(this.awsSecretKey)) {
196197
aws = AWSClients.fromDefaultCredentialChain(
@@ -220,8 +221,13 @@ public boolean perform(AbstractBuild build, Launcher launcher, BuildListener lis
220221

221222
verifyCodeDeployApplication(aws);
222223

223-
String projectName = build.getProject().getName();
224-
RevisionLocation revisionLocation = zipAndUpload(aws, projectName, getSourceDirectory(build.getWorkspace()));
224+
final String projectName = build.getProject().getName();
225+
final FilePath workspace = build.getWorkspace();
226+
if (workspace == null) {
227+
throw new IllegalArgumentException("No workspace present for the build.");
228+
}
229+
final FilePath sourceDirectory = getSourceDirectory(workspace);
230+
final RevisionLocation revisionLocation = zipAndUpload(aws, projectName, sourceDirectory);
225231

226232
registerRevision(aws, revisionLocation);
227233
if ("onlyRevision".equals(deploymentMethod)){
@@ -296,10 +302,10 @@ private RevisionLocation zipAndUpload(AWSClients aws, String projectName, FilePa
296302
File versionFile;
297303
versionFile = new File(sourceDirectory + "/" + versionFileName);
298304

299-
FileReader reader = null;
305+
InputStreamReader reader = null;
300306
String version = null;
301307
try {
302-
reader = new FileReader(versionFile);
308+
reader = new InputStreamReader(new FileInputStream(versionFile), "UTF-8");
303309
char[] chars = new char[(int) versionFile.length() -1];
304310
reader.read(chars);
305311
version = new String(chars);
@@ -312,7 +318,10 @@ private RevisionLocation zipAndUpload(AWSClients aws, String projectName, FilePa
312318

313319
if (version != null){
314320
zipFile = new File("/tmp/" + projectName + "-" + version + ".zip");
315-
zipFile.createNewFile();
321+
final boolean fileCreated = zipFile.createNewFile();
322+
if (!fileCreated) {
323+
logger.println("File already exists, overwriting: " + zipFile.getPath());
324+
}
316325
} else {
317326
zipFile = File.createTempFile(projectName + "-", ".zip");
318327
}
@@ -344,12 +353,15 @@ private RevisionLocation zipAndUpload(AWSClients aws, String projectName, FilePa
344353

345354
logger.println("Zipping files into " + zipFile.getAbsolutePath());
346355

347-
348-
349-
sourceDirectory.zip(
350-
new FileOutputStream(zipFile),
351-
new DirScanner.Glob(this.includes, this.excludes)
352-
);
356+
FileOutputStream outputStream = new FileOutputStream(zipFile);
357+
try {
358+
sourceDirectory.zip(
359+
outputStream,
360+
new DirScanner.Glob(this.includes, this.excludes)
361+
);
362+
} finally {
363+
outputStream.close();
364+
}
353365

354366
if (prefix.isEmpty()) {
355367
key = zipFile.getName();
@@ -376,7 +388,10 @@ private RevisionLocation zipAndUpload(AWSClients aws, String projectName, FilePa
376388

377389
return revisionLocation;
378390
} finally {
379-
zipFile.delete();
391+
final boolean deleted = zipFile.delete();
392+
if (!deleted) {
393+
logger.println("Failed to clean up file " + zipFile.getPath());
394+
}
380395
}
381396
}
382397

@@ -531,7 +546,7 @@ public boolean configure(StaplerRequest req, JSONObject formData) throws FormExc
531546
awsAccessKey = formData.getString("awsAccessKey");
532547
awsSecretKey = formData.getString("awsSecretKey");
533548
proxyHost = formData.getString("proxyHost");
534-
proxyPort = Integer.valueOf(formData.getString("proxyPort"));
549+
proxyPort = Integer.parseInt(formData.getString("proxyPort"));
535550

536551
req.bindJSON(this, formData);
537552
save();

src/main/resources/com/amazonaws/codedeploy/AWSCodeDeployPublisher/config.jelly

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<?jelly escape-by-default='true'?>
12
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
23
<f:entry title="AWS CodeDeploy Application Name" field="applicationName">
34
<f:textbox />

src/main/resources/com/amazonaws/codedeploy/AWSCodeDeployPublisher/global.jelly

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<?jelly escape-by-default='true'?>
12
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
23
<f:section title="AWS CodeDeploy Credentials">
34
<f:description>

src/main/resources/index.jelly

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<?jelly escape-by-default='true'?>
12
<div>
23
This plugin provides a "post-build" step for AWS CodeDeploy.
34
</div>

0 commit comments

Comments
 (0)