Refactor some common code in Jenkins.