Chapter 19. Long-Running Build Plugin

Introduction

What happens to builds that were running when Jenkins crashes, or is restarted not in “safe” mode (waiting for running builds to complete)? Whether or not you are using High Availability to start another Jenkins master, builds of regular projects that were already running will be aborted. The Restart Aborted Builds plugin will at least let you find and reschedule them. But for builds of projects which normally take a long time, perhaps hours or even days, this is not enough.

To address the needs of people who have builds that are just too long to interrupt every time a Jenkins slave agent is reconnected (or Jenkins is restarted for a plugin update!), Jenkins Enterprise includes a plugin offering a “long-running” project type. The configuration is almost the same as for a standard free-style project, with one difference: the part of your build that you want to run apart from Jenkins should be configured as a (Unix) shell or (Windows) batch step. Of course this script could in turn run Maven, Make, or other tools.

If the slave agent is reconnected or Jenkins restarted during this “detached build” phase, your build keeps on running uninterrupted on the slave machine (so long as that machine is not rebooted of course). When Jenkins makes contact with the slave again, it will continue to show log messages where it left off, and let the build continue. After the main phase is done, you can run the usual post-build steps, such as archiving artifacts or recording JUnit-style test results.

The Long-Running Build plugin was introduced in Jenkins Enterprise 14.05.