How to re-build task on Jenkins until build succeed?

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.


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.