Fix JENKINS-22610

Added check if the returned value from getTemplateById is null. Write
error to the build log if the template is missing.