[JENKINS-20609] refactored script hook

in preparation of introducing other hooks
doc improvements
recover from exception
defining hooks  for customizing variable bindings
[FIXED JENKINS-20609]

Implemented the hook