How to Retry a Failed Build in Jenkins?
Retry builds after failure in Jenkins
- Open Jenkins using the URL: http://localhost:8080/ on any browser.
2. Click the ‘Manage Jenkins’ menu displayed on the right side of the screen. You will be redirected to the ‘Manage Jenkins’ page, where you need to select the ‘Manage Plugins’ option.
4. Enter ‘Naginator’ in the ‘Filter’ field displayed at the right side of ‘Manage Plugins’ page. It will display the ‘Naginator Plugin’ option. Select the option and click the ‘Install without restart’ button.
5. Now go to the home page and click on the created job. Click the ‘Configure’ button.
6. You will be redirected to the ’Testing’ job project, where you need to click the ‘Configure’ link displayed at the left side of the page.
7. Choose the ‘Add post build action’ option from the dropdown as shown below.
8. Now select the ‘Retry Build after failure’ field.
9. You will see the ’Retry build after failure’ configuration section being displayed.
10. There are 3 configuration settings (as numbered in the above image). Let’s discuss each in detail.
- Setting 1 -> Rerun build for unstable builds as well as failures
This option indicates whether you should retry the UNSTABLE state builds in addition to FAILURE state builds. So, let’s set it to true.
- Setting 2 -> Delay before the schedule
This allows you to define how long to delay retrying build start-time from the time it was failed. There are two options to choose from; one is to provide a “fixed period” and the other is to provide an “increasing period”. So, let’s use fixed period; and set it to 180 (3 minutes).
- Setting 3 -> Max number of successive failed build
This is used to control the number of continuous failure builds. Jenkins will not automatically retry more than this maximum number of consecutive failures. So, let’s set 2, so that it is retried only two times.
11. Now, run the build and see it executing two times after the failure.