Skip to content

Commit e46d0ef

Browse files
committed
Merge pull request awslabs#38 from cojennin/deployment-group-name-env-variable
AWS CodeDeploy Deployment Group environment variable value ovewrites field value
2 parents a03b0f6 + 01d5ea6 commit e46d0ef

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public class AWSCodeDeployPublisher extends Publisher {
8282
private final String s3bucket;
8383
private final String s3prefix;
8484
private final String applicationName;
85-
private String deploymentGroupName; // TODO allow for deployment to multiple groups
85+
private final String deploymentGroupName; // TODO allow for deployment to multiple groups
8686
private final String deploymentConfig;
8787
private final Long pollingTimeoutSec;
8888
private final Long pollingFreqSec;
@@ -214,15 +214,15 @@ public boolean perform(AbstractBuild build, Launcher launcher, BuildListener lis
214214
try {
215215

216216
Map<String, String> envVars = build.getEnvironment(listener);
217-
this.deploymentGroupName = Util.replaceMacro(this.deploymentGroupName, envVars);
217+
String deploymentGroupName = Util.replaceMacro(this.deploymentGroupName, envVars);
218218

219-
verifyCodeDeployApplication(aws);
219+
verifyCodeDeployApplication(aws, deploymentGroupName);
220220

221221
String projectName = build.getProject().getName();
222-
RevisionLocation revisionLocation = zipAndUpload(aws, projectName, getSourceDirectory(build.getWorkspace()), envVars);
222+
RevisionLocation revisionLocation = zipAndUpload(aws, projectName, getSourceDirectory(build.getWorkspace()), envVars, deploymentGroupName);
223223

224224
registerRevision(aws, revisionLocation);
225-
String deploymentId = createDeployment(aws, revisionLocation);
225+
String deploymentId = createDeployment(aws, revisionLocation, deploymentGroupName);
226226

227227
success = waitForDeployment(aws, deploymentId);
228228

@@ -262,7 +262,7 @@ private boolean isSubDirectory(FilePath parent, FilePath child) {
262262
return false;
263263
}
264264

265-
private void verifyCodeDeployApplication(AWSClients aws) throws IllegalArgumentException {
265+
private void verifyCodeDeployApplication(AWSClients aws, String deploymentGroupName) throws IllegalArgumentException {
266266
// Check that the application exists
267267
ListApplicationsResult applications = aws.codedeploy.listApplications();
268268

@@ -276,27 +276,27 @@ private void verifyCodeDeployApplication(AWSClients aws) throws IllegalArgumentE
276276
.withApplicationName(this.applicationName)
277277
);
278278

279-
if (!deploymentGroups.getDeploymentGroups().contains(this.deploymentGroupName)) {
280-
throw new IllegalArgumentException("Cannot find deployment group named '" + this.deploymentGroupName + "'");
279+
if (!deploymentGroups.getDeploymentGroups().contains(deploymentGroupName)) {
280+
throw new IllegalArgumentException("Cannot find deployment group named '" + deploymentGroupName + "'");
281281
}
282282
}
283283

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

286286
File zipFile = File.createTempFile(projectName + "-", ".zip");
287287
String key;
288288
File appspec;
289289
File dest;
290290
try {
291291
if (this.deploymentGroupAppspec) {
292-
appspec = new File(sourceDirectory + "/appspec." + this.deploymentGroupName + ".yml");
292+
appspec = new File(sourceDirectory + "/appspec." + deploymentGroupName + ".yml");
293293
if (appspec.exists()) {
294294
dest = new File(sourceDirectory + "/appspec.yml");
295295
FileUtils.copyFile(appspec, dest);
296-
logger.println("Use appspec." + this.deploymentGroupName + ".yml");
296+
logger.println("Use appspec." + deploymentGroupName + ".yml");
297297
}
298298
if (!appspec.exists()) {
299-
throw new IllegalArgumentException("/appspec." + this.deploymentGroupName + ".yml file does not exist" );
299+
throw new IllegalArgumentException("/appspec." + deploymentGroupName + ".yml file does not exist" );
300300
}
301301

302302
}
@@ -352,14 +352,14 @@ private void registerRevision(AWSClients aws, RevisionLocation revisionLocation)
352352
);
353353
}
354354

355-
private String createDeployment(AWSClients aws, RevisionLocation revisionLocation) throws Exception {
355+
private String createDeployment(AWSClients aws, RevisionLocation revisionLocation, String deploymentGroupName) throws Exception {
356356

357357
this.logger.println("Creating deployment with revision at " + revisionLocation);
358358

359359
CreateDeploymentResult createDeploymentResult = aws.codedeploy.createDeployment(
360360
new CreateDeploymentRequest()
361361
.withDeploymentConfigName(this.deploymentConfig)
362-
.withDeploymentGroupName(this.deploymentGroupName)
362+
.withDeploymentGroupName(deploymentGroupName)
363363
.withApplicationName(this.applicationName)
364364
.withRevision(revisionLocation)
365365
.withDescription("Deployment created by Jenkins")

0 commit comments

Comments
 (0)