-
Notifications
You must be signed in to change notification settings - Fork 131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Propagate job cancellation to CodeDeploy #41
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,8 @@ | |
import com.amazonaws.services.codedeploy.model.GetDeploymentRequest; | ||
import com.amazonaws.services.codedeploy.model.RegisterApplicationRevisionRequest; | ||
import com.amazonaws.services.codedeploy.model.S3Location; | ||
import com.amazonaws.services.codedeploy.model.StopDeploymentRequest; | ||
import com.amazonaws.services.codedeploy.model.StopDeploymentResult; | ||
|
||
import hudson.FilePath; | ||
import hudson.Launcher; | ||
|
@@ -210,6 +212,7 @@ public boolean perform(AbstractBuild build, Launcher launcher, BuildListener lis | |
} | ||
|
||
boolean success; | ||
String deploymentId = null; | ||
|
||
try { | ||
|
||
|
@@ -222,10 +225,21 @@ public boolean perform(AbstractBuild build, Launcher launcher, BuildListener lis | |
RevisionLocation revisionLocation = zipAndUpload(aws, projectName, getSourceDirectory(build.getWorkspace()), envVars); | ||
|
||
registerRevision(aws, revisionLocation); | ||
String deploymentId = createDeployment(aws, revisionLocation); | ||
deploymentId = createDeployment(aws, revisionLocation); | ||
|
||
success = waitForDeployment(aws, deploymentId); | ||
|
||
} catch (InterruptedException e) { | ||
|
||
this.logger.println("User cancelling CodeDeploy job"); | ||
try { | ||
this.logger.println(stopDeployment(aws, deploymentId)); | ||
} catch (Exception ex) { | ||
this.logger.println(e.getMessage()); | ||
e.printStackTrace(this.logger); | ||
} | ||
success = false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the stopDeployment fails because the deployment completed successfully, we shouldn't fail the job, but actually mark it as successful. |
||
|
||
} catch (Exception e) { | ||
|
||
this.logger.println("Failed CodeDeploy post-build step; exception follows."); | ||
|
@@ -368,6 +382,18 @@ private String createDeployment(AWSClients aws, RevisionLocation revisionLocatio | |
return createDeploymentResult.getDeploymentId(); | ||
} | ||
|
||
private String stopDeployment(AWSClients aws, String deploymentId) throws Exception { | ||
|
||
this.logger.println("Stopping deployment " + deploymentId); | ||
|
||
StopDeploymentResult stopDeploymentResult = aws.codedeploy.stopDeployment( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Stopping a deployment might not be immediate. We might want to wait for the deployment to actually stop before continuing. |
||
new StopDeploymentRequest() | ||
.withDeploymentId(deploymentId) | ||
); | ||
|
||
return stopDeploymentResult.getStatus(); | ||
} | ||
|
||
private boolean waitForDeployment(AWSClients aws, String deploymentId) throws InterruptedException { | ||
|
||
if (!this.waitForCompletion) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
deploymentId might be null here, we should handle that case.