Extract class responsible for building a pipeline Closes #38460 See merge request gitlab-org/gitlab-ce!14762