5050import net .sf .json .JSONObject ;
5151
5252import org .apache .commons .lang .StringUtils ;
53+ import org .apache .commons .io .FileUtils ;
5354import org .kohsuke .stapler .DataBoundConstructor ;
5455import org .kohsuke .stapler .QueryParameter ;
5556import 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 }
0 commit comments