Backport changes introduced by https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/1078
What does this MR do?
This MR backport changes introduced by: https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/1078 which refactor a little builds picking code.
It is meant to make it easier in future to merge CE to EE.