I have done extensive research for Continuous Integration and Delivery and I had a requirement where the nightly deployment should rollback in case the Deployment Failed.
I had used Jenkins coupled with Octopus Deploy for implementing a CI/CD Infrastructure. I was a bit skeptical whether this could be possible but yes it is possible!
Jenkins keeps track of the build status and outputs either SUCCESS or FAILURE at the end of the build. While the build is running, there is no way to keep track of the status since the build has not yet completed. I have a Jenkins job which triggers octo.exe through the windows batch command step to deploy to octopus deploy.
In case the deployment fails, the build job will fail. I have added another monitor job which is triggered despite the build has failed. The monitoring job contains the URL of the previous build job – for e.g. http://localhost:8081/Jenkins/Deploy/build/41/console
I use powershell to read the status of the log – either SUCCESS or FAILURE, based on the output, I trigger the deployment of a previous release in Octopus Deploy.