Fix for JENKINS-14725

This commit should fix JENKINS-14725. 
The current implementation doesn't keep in mind the possibility of using promote builds.