50
50
import net .sf .json .JSONObject ;
51
51
52
52
import org .apache .commons .lang .StringUtils ;
53
+ import org .apache .commons .io .FileUtils ;
53
54
import org .kohsuke .stapler .DataBoundConstructor ;
54
55
import org .kohsuke .stapler .QueryParameter ;
55
56
import org .kohsuke .stapler .StaplerRequest ;
@@ -85,6 +86,7 @@ public class AWSCodeDeployPublisher extends Publisher {
85
86
private final String deploymentConfig ;
86
87
private final Long pollingTimeoutSec ;
87
88
private final Long pollingFreqSec ;
89
+ private final boolean deploymentGroupAppspec ;
88
90
private final boolean waitForCompletion ;
89
91
private final String externalId ;
90
92
private final String iamRoleArn ;
@@ -110,6 +112,7 @@ public AWSCodeDeployPublisher(
110
112
String deploymentGroupName ,
111
113
String deploymentConfig ,
112
114
String region ,
115
+ Boolean deploymentGroupAppspec ,
113
116
Boolean waitForCompletion ,
114
117
Long pollingTimeoutSec ,
115
118
Long pollingFreqSec ,
@@ -142,6 +145,7 @@ public AWSCodeDeployPublisher(
142
145
this .awsAccessKey = awsAccessKey ;
143
146
this .awsSecretKey = awsSecretKey ;
144
147
this .iamRoleArn = iamRoleArn ;
148
+ this .deploymentGroupAppspec = deploymentGroupAppspec ;
145
149
146
150
if (waitForCompletion != null && waitForCompletion ) {
147
151
this .waitForCompletion = waitForCompletion ;
@@ -277,13 +281,29 @@ private void verifyCodeDeployApplication(AWSClients aws) throws IllegalArgumentE
277
281
}
278
282
}
279
283
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 {
281
285
282
286
File zipFile = File .createTempFile (projectName + "-" , ".zip" );
283
287
String key ;
284
-
288
+ File appspec ;
289
+ File dest ;
285
290
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
+
287
307
288
308
sourceDirectory .zip (
289
309
new FileOutputStream (zipFile ),
@@ -611,6 +631,10 @@ public boolean getWaitForCompletion() {
611
631
return waitForCompletion ;
612
632
}
613
633
634
+ public boolean getDeploymentGroupAppspec () {
635
+ return deploymentGroupAppspec ;
636
+ }
637
+
614
638
public String getCredentials () {
615
639
return credentials ;
616
640
}
0 commit comments