To manage rollbacks in Jenkins pipelines for deployments that failed, logic should be applied to validate the success of every deployment. In the event of a failed deployment, the pipeline is automatically triggered into a rollback of the previous stable version.
Rollback Strategy
Deploy New Version: This will deploy the newest version of the application.
Verify Deployment: Run the deployment. Report if it fails, which would trigger a rollback.
Roll back to previous version: revert to last successful deployment.
Sample Jenkinsfile with Rollback Logic
Explanation
Deploy the New Version: It deploys the latest version with rollback logic in case of errors.
Test deployment: It tests the deployment; while testing, if there is a failure in a test, it will roll back to the previous version.
This configuration offers a roll-back mechanism that is safe. It will lead to stability due to rolling back at the point of failure to a known good state.