Tristan build sha if exists
This is a admittedly a bit lame, but less complicated than refactoring ybd thoughout.
Basically we just take Paul's original MR, and store the original ref in the definitions tree for the duration of the run, restoring the ref only in the output exported target.yml file.
The behavior is however correct.