Afterbuild restart reworked. Fixed issue JENKINS-19688.