[JENKINS-14575] Fix regression and add tests as well

Since the big refactor, the bug JENKINS-1457 is back. This PR will fixes the SCM retry again. But this time I add the tests as well.