20

I have a Jenkins job which requires a several build attepmts until it is built successfully, is there a way to keep re-building the job automatically until the job is done?

barha
  • 709
  • 1
  • 7
  • 22

3 Answers3

28

If your build is expected to require more than one attempt to succeed, I would fix the build first.

To retry a Jenkins job, you can use the Naginator plugin.

Configuration

Simply install the plugin, and then check the Post-Build action "Retry build after failure" on your project's configuration page.

If the build fails, it will be rescheduled to run again after the time you specified. You can choose how many times to retry running the job. For each consecutive unsuccessful build, you can choose to extend the waiting period.

The following options are also available:

  • Rerun build for unstable builds as well as failures
  • Only rebuild the job if the build's log output contains a given regular expression
  • Rerun build only for the failed parts of a matrix job

The plugin also adds a rerun button for in the build section.

jvnill
  • 29,479
  • 4
  • 83
  • 86
Martin
  • 3,960
  • 7
  • 43
  • 43
  • it is happening during the authentication stage with IBM Bluemix, which might take few tries until you get authenticated (even though your key is correct). thanks for helping. – barha Jun 15 '17 at 16:11
1

I haven't tried it myself, but a quick Google turned up the Naginator Plugin, which appears to do what you're asking.

Obligatory side note: better to fix your build for real, though.

oeuftete
  • 2,628
  • 1
  • 24
  • 33
0

While fixing your build is always a good approach, sometimes success is determined by a third-party service. For example, an API endpoint goes down and the tests start failing. I want this build to rerun until success, then marked as such. I have created a second job, that is taking only the output of the last successful build and running tests periodically against it. So what we get is a monitoring service against the last known good build AND an automatic retry system for the development branch build system.