Jenkins : Groovy Hook Script

In several places inside Jenkins, a series of "hook scripts" get executed to allow some actions to take place in reaction to some key events.

These scripts are written in Groovy, and get executed inside the same JVM as Jenkins, allowing full access to the domain model of Jenkins. For given hook HOOK, the following locations are searched:

  • WEB-INF/HOOK.groovy in jenkins.war
  • WEB-INF/HOOK.groovy.d/*.groovy in the lexical order in jenkins.war
  • $JENKINS_HOME/HOOK.groovy
  • $JENKINS_HOME/HOOK.groovy.d/*.groovy in the lexical order

HOOK.groovy.d is suitable to avoid conflicts — multiple entities can insert stuff into the hook without worrying about overwriting each other's code.

The following events use this mechanism: