Skip to content

Commit 3014d9b

Browse files
committed
Merge pull request #27 from grusy/appspec
add option to have a dedicated appsec.yml file per deployment group
2 parents ab57672 + 5de25a5 commit 3014d9b

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

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

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
import net.sf.json.JSONObject;
5151

5252
import org.apache.commons.lang.StringUtils;
53+
import org.apache.commons.io.FileUtils;
5354
import org.kohsuke.stapler.DataBoundConstructor;
5455
import org.kohsuke.stapler.QueryParameter;
5556
import org.kohsuke.stapler.StaplerRequest;
@@ -85,6 +86,7 @@ public class AWSCodeDeployPublisher extends Publisher {
8586
private final String deploymentConfig;
8687
private final Long pollingTimeoutSec;
8788
private final Long pollingFreqSec;
89+
private final boolean deploymentGroupAppspec;
8890
private final boolean waitForCompletion;
8991
private final String externalId;
9092
private final String iamRoleArn;
@@ -110,6 +112,7 @@ public AWSCodeDeployPublisher(
110112
String deploymentGroupName,
111113
String deploymentConfig,
112114
String region,
115+
Boolean deploymentGroupAppspec,
113116
Boolean waitForCompletion,
114117
Long pollingTimeoutSec,
115118
Long pollingFreqSec,
@@ -142,6 +145,7 @@ public AWSCodeDeployPublisher(
142145
this.awsAccessKey = awsAccessKey;
143146
this.awsSecretKey = awsSecretKey;
144147
this.iamRoleArn = iamRoleArn;
148+
this.deploymentGroupAppspec = deploymentGroupAppspec;
145149

146150
if (waitForCompletion != null && waitForCompletion) {
147151
this.waitForCompletion = waitForCompletion;
@@ -277,13 +281,29 @@ private void verifyCodeDeployApplication(AWSClients aws) throws IllegalArgumentE
277281
}
278282
}
279283

280-
private RevisionLocation zipAndUpload(AWSClients aws, String projectName, FilePath sourceDirectory, Map<String, String> envVars) throws IOException, InterruptedException {
284+
private RevisionLocation zipAndUpload(AWSClients aws, String projectName, FilePath sourceDirectory, Map<String, String> envVars) throws IOException, InterruptedException, IllegalArgumentException {
281285

282286
File zipFile = File.createTempFile(projectName + "-", ".zip");
283287
String key;
284-
288+
File appspec;
289+
File dest;
285290
try {
286-
this.logger.println("Zipping files into " + zipFile.getAbsolutePath());
291+
if (this.deploymentGroupAppspec) {
292+
appspec = new File(sourceDirectory + "/appspec." + this.deploymentGroupName + ".yml");
293+
if (appspec.exists()) {
294+
dest = new File(sourceDirectory + "/appspec.yml");
295+
FileUtils.copyFile(appspec, dest);
296+
logger.println("Use appspec." + this.deploymentGroupName + ".yml");
297+
}
298+
if (!appspec.exists()) {
299+
throw new IllegalArgumentException("/appspec." + this.deploymentGroupName + ".yml file does not exist" );
300+
}
301+
302+
}
303+
304+
logger.println("Zipping files into " + zipFile.getAbsolutePath());
305+
306+
287307

288308
sourceDirectory.zip(
289309
new FileOutputStream(zipFile),
@@ -611,6 +631,10 @@ public boolean getWaitForCompletion() {
611631
return waitForCompletion;
612632
}
613633

634+
public boolean getDeploymentGroupAppspec() {
635+
return deploymentGroupAppspec;
636+
}
637+
614638
public String getCredentials() {
615639
return credentials;
616640
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@
3333
<f:textbox default="" />
3434
</f:entry>
3535

36+
<f:entry title="Appspec.yml per Deployment Group" field="deploymentGroupAppspec">
37+
<f:checkbox field="deploymentGroupAppspec" checked="${instance.getDeploymentGroupAppspec}"/>
38+
</f:entry>
39+
3640
<f:optionalBlock title="Wait for deployment to finish?" field="waitForCompletion" checked="${instance.getWaitForCompletion()}" inline="true">
3741
<f:entry title="Polling Timeout (s)" field="pollingTimeoutSec">
3842
<f:textbox default="300"/>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<div>
2+
<p>If checked, the build will use a dedicated appspec.yml file per deployment group.<br><br>
3+
<p>e.g.: appsec.staging.yml</p>
4+
</div>

0 commit comments

Comments
 (0)