Our deployment process requires a reboot and the end of the project and emails a success email when this succeeds to indicate a successful deployment. However, now on a more frequent occasion this step, we receive the following error:
The step failed: Activity Restart Server on XXXXXXX failed with error ‘An error occurred when sending a request to ‘XXXXXXXX/’, after the request began: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. An existing connection was forcibly closed by the remote host’.
we are using a simple powershell script to execute the reboot:
Restart-Computer -ComputerName “localhost” -Force
The reboot is successful, but the deploy is marked as failed.
Is there a way to either always mark as successful or best practice to handle reboots in a deploy project?
There is a way to mark as successful, by design this is a manual process. This can be done on the Deployment task screen by selecting the overflow menu in the top right corner and choosing Edit State:
You can then change the state of the task to Success and input a reason why. I wouldn’t recommend this approach in your case though.
What I would recommend that you do is configure this project to allow for a restart. This is fairly straightforward, but does require a couple of changes. Step one is to allow for a machine to go offline during the deployment, to do that you need to go to the Settings page for the project and change the option to Skip deployment targets if they are or become unavailable
Once that is done you can use your existing step to trigger the restart, however you will need to add two more steps to your project after the reboot step. The first is a wait step, which is simply a script step with a start-sleep in it with enough time to allow for the server to reboot. This step must run on server otherwise it will fail if you try to run it on the deployment target that is restarting .
Once that step completes and the server is [hopefully] back online we need to re-add it to the deployment manifest as it may have been removed during the restart (see Skip deployment targets). This is done by adding a Health Check step which will re-add the machine to the available targets. Once you have added the step I would recommend changing two of the options:
Health check type -> Perform a connection-only test [much faster]
New Deployment Targets -> Include new deployment targets in the deployment [to re-add the machine if it had been removed]