Skip to content

Commit 1473051

Browse files
committed
Merge branch 'master' of git://github.com/wspi/aws-codedeploy-plugin into wspi-master
Conflicts: pom.xml
2 parents a39a1ca + 26bc6a1 commit 1473051

File tree

2 files changed

+73
-18
lines changed

2 files changed

+73
-18
lines changed

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

Lines changed: 50 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757

5858
import java.io.File;
5959
import java.io.FileOutputStream;
60+
import java.io.FileReader;
6061
import java.io.IOException;
6162
import java.io.PrintStream;
6263
import java.util.Date;
@@ -100,6 +101,8 @@ public class AWSCodeDeployPublisher extends Publisher {
100101
private final String awsAccessKey;
101102
private final String awsSecretKey;
102103
private final String credentials;
104+
private final String deploymentMethod;
105+
private final String versionFileName;
103106

104107
private PrintStream logger;
105108
private Map <String, String> envVars;
@@ -117,6 +120,8 @@ public AWSCodeDeployPublisher(
117120
Long pollingTimeoutSec,
118121
Long pollingFreqSec,
119122
String credentials,
123+
String versionFileName,
124+
String deploymentMethod,
120125
String awsAccessKey,
121126
String awsSecretKey,
122127
String iamRoleArn,
@@ -142,6 +147,8 @@ public AWSCodeDeployPublisher(
142147
this.proxyHost = proxyHost;
143148
this.proxyPort = proxyPort;
144149
this.credentials = credentials;
150+
this.deploymentMethod = deploymentMethod;
151+
this.versionFileName = versionFileName;
145152
this.awsAccessKey = awsAccessKey;
146153
this.awsSecretKey = awsSecretKey;
147154
this.iamRoleArn = iamRoleArn;
@@ -165,7 +172,6 @@ public AWSCodeDeployPublisher(
165172
this.pollingFreqSec = null;
166173
}
167174

168-
169175
this.s3bucket = s3bucket;
170176
if (s3prefix == null || s3prefix.equals("/") || s3prefix.length() == 0) {
171177
this.s3prefix = "";
@@ -218,9 +224,14 @@ public boolean perform(AbstractBuild build, Launcher launcher, BuildListener lis
218224
RevisionLocation revisionLocation = zipAndUpload(aws, projectName, getSourceDirectory(build.getWorkspace()));
219225

220226
registerRevision(aws, revisionLocation);
221-
String deploymentId = createDeployment(aws, revisionLocation);
227+
if ("onlyRevision".equals(deploymentMethod)){
228+
success = true;
229+
} else {
230+
231+
String deploymentId = createDeployment(aws, revisionLocation);
222232

223-
success = waitForDeployment(aws, deploymentId);
233+
success = waitForDeployment(aws, deploymentId);
234+
}
224235

225236
} catch (Exception e) {
226237

@@ -263,7 +274,7 @@ private void verifyCodeDeployApplication(AWSClients aws) throws IllegalArgumentE
263274
ListApplicationsResult applications = aws.codedeploy.listApplications();
264275
String applicationName = getApplicationNameFromEnv();
265276
String deploymentGroupName = getDeploymentGroupNameFromEnv();
266-
277+
267278
if (!applications.getApplications().contains(applicationName)) {
268279
throw new IllegalArgumentException("Cannot find application named '" + applicationName + "'");
269280
}
@@ -281,7 +292,31 @@ private void verifyCodeDeployApplication(AWSClients aws) throws IllegalArgumentE
281292

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

284-
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+
285320
String key;
286321
File appspec;
287322
File dest;
@@ -329,7 +364,6 @@ private RevisionLocation zipAndUpload(AWSClients aws, String projectName, FilePa
329364
logger.println("Uploading zip to s3://" + bucket + "/" + key);
330365
PutObjectResult s3result = aws.s3.putObject(bucket, key, zipFile);
331366

332-
333367
S3Location s3Location = new S3Location();
334368
s3Location.setBucket(bucket);
335369
s3Location.setKey(key);
@@ -418,9 +452,9 @@ private boolean waitForDeployment(AWSClients aws, String deploymentId) throws In
418452

419453
Thread.sleep(pollingFreqMillis);
420454
}
421-
455+
422456
logger.println("Deployment status: " + deployStatus.getStatus() + "; instances: " + deployStatus.getDeploymentOverview());
423-
457+
424458
if (!deployStatus.getStatus().equals(DeploymentStatus.Succeeded.toString())) {
425459
this.logger.println("Deployment did not succeed. Final status: " + deployStatus.getStatus());
426460
success = false;
@@ -634,6 +668,14 @@ public String getExternalId() {
634668
return externalId;
635669
}
636670

671+
public String getDeploymentMethod() {
672+
return deploymentMethod;
673+
}
674+
675+
public String getVersionFileName() {
676+
return versionFileName;
677+
}
678+
637679
public boolean getWaitForCompletion() {
638680
return waitForCompletion;
639681
}
@@ -690,4 +732,3 @@ public String getS3PrefixFromEnv() {
690732
return Util.replaceMacro(this.s3prefix, envVars);
691733
}
692734
}
693-

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

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,36 @@
2929
<f:entry title="Proxy Host" field="proxyHost">
3030
<f:textbox default="" />
3131
</f:entry>
32-
<f:entry title="Proxy Port" field="proxyPort">
32+
<f:entry title="Proxy Port" field="proxyPort">
3333
<f:textbox default="" />
3434
</f:entry>
35+
<f:entry title="Version File" field="versionFileName">
36+
<f:textbox />
37+
</f:entry>
3538

3639
<f:entry title="Appspec.yml per Deployment Group" field="deploymentGroupAppspec">
3740
<f:checkbox field="deploymentGroupAppspec" checked="${instance.getDeploymentGroupAppspec}"/>
3841
</f:entry>
3942

40-
<f:optionalBlock title="Wait for deployment to finish?" field="waitForCompletion" checked="${instance.getWaitForCompletion()}" inline="true">
41-
<f:entry title="Polling Timeout (s)" field="pollingTimeoutSec">
42-
<f:textbox default="300"/>
43-
</f:entry>
44-
<f:entry title="Polling Frequency (s)" field="pollingFreqSec">
45-
<f:textbox default="15"/>
46-
</f:entry>
47-
</f:optionalBlock>
43+
<f:radioBlock title="Revision Only" name="deploymentMethod" value="onlyRevision" checked="${instance.getDeploymentMethod() == 'onlyRevision'}" inline="true">
44+
<f:description>
45+
If it's selected, the plugin will only generate the revision and won't deploy.
46+
</f:description>
47+
</f:radioBlock>
48+
49+
<f:radioBlock title="Deploy" name="deploymentMethod" value="deploy" checked="${instance.getDeploymentMethod() == 'deploy'}" inline="true">
50+
<f:description>
51+
If it's selected, the plugin will generate the revision and will deploy.
52+
</f:description>
53+
<f:optionalBlock title="Wait for deployment to finish?" field="waitForCompletion" checked="${instance.getWaitForCompletion()}" inline="true">
54+
<f:entry title="Polling Timeout (s)" field="pollingTimeoutSec">
55+
<f:textbox default="300"/>
56+
</f:entry>
57+
<f:entry title="Polling Frequency (s)" field="pollingFreqSec">
58+
<f:textbox default="15"/>
59+
</f:entry>
60+
</f:optionalBlock>
61+
</f:radioBlock>
4862

4963
<f:radioBlock title="Use Access/Secret keys" name="credentials" checked="${instance.getCredentials() == 'awsAccessKey'}" inline="true" value="awsAccessKey">
5064
<f:description>

0 commit comments

Comments
 (0)