[FIX JENKINS-14538] Improve builds dir input validation
[JENKINS-14583] Move replacement into shared function for reuse
[JENKINS-14583] Fix tests
Merge pull request #1251 from daniel-beck/JENKINS-14583

[FIX JENKINS-14538] Improve builds dir input validation