Skip to content

Commit ba4cd55

Browse files
author
Martin Guenthner
committed
add option to have a dedicated appsec.yml file per deployment group
1 parent c79b817 commit ba4cd55

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;
@@ -274,13 +278,29 @@ private void verifyCodeDeployApplication(AWSClients aws) throws IllegalArgumentE
274278
}
275279
}
276280

277-
private RevisionLocation zipAndUpload(AWSClients aws, String projectName, FilePath sourceDirectory, Map<String, String> envVars) throws IOException, InterruptedException {
281+
private RevisionLocation zipAndUpload(AWSClients aws, String projectName, FilePath sourceDirectory, Map<String, String> envVars) throws IOException, InterruptedException, IllegalArgumentException {
278282

279283
File zipFile = File.createTempFile(projectName + "-", ".zip");
280284
String key;
281-
285+
File appspec;
286+
File dest;
282287
try {
283-
this.logger.println("Zipping files into " + zipFile.getAbsolutePath());
288+
if (this.deploymentGroupAppspec) {
289+
appspec = new File(sourceDirectory + "/appspec." + this.deploymentGroupName + ".yml");
290+
if (appspec.exists()) {
291+
dest = new File(sourceDirectory + "/appspec.yml");
292+
FileUtils.copyFile(appspec, dest);
293+
logger.println("Use appspec." + this.deploymentGroupName + ".yml");
294+
}
295+
if (!appspec.exists()) {
296+
throw new IllegalArgumentException("/appspec." + this.deploymentGroupName + ".yml file does not exist" );
297+
}
298+
299+
}
300+
301+
logger.println("Zipping files into " + zipFile.getAbsolutePath());
302+
303+
284304

285305
sourceDirectory.zip(
286306
new FileOutputStream(zipFile),
@@ -606,6 +626,10 @@ public boolean getWaitForCompletion() {
606626
return waitForCompletion;
607627
}
608628

629+
public boolean getDeploymentGroupAppspec() {
630+
return deploymentGroupAppspec;
631+
}
632+
609633
public String getCredentials() {
610634
return credentials;
611635
}

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)