## 12.6 Hooking into Build Events

#### Post-Install Configuration and Participating in Upgrades

Grails plug-ins can do post-install configuration and participate in application upgrade process (the upgrade command). This is achieved via two specially named scripts under `scripts` directory of the plugin - `_Install.groovy` and `_Upgrade.groovy`.

`_Install.groovy` is executed after the plugin has been installed and `_Upgrade.groovy` is executed each time the user upgrades his application with upgrade command.

These scripts are normal Gant scripts so you can use the full power of Gant. An addition to the standard Gant variables is the `pluginBasedir` variable which points at the plugin installation basedir.

As an example the below `_Install.groovy` script will create a new directory type under the `grails-app` directory and install a configuration template:

    Ant.mkdir(dir:"${basedir}/grails-app/jobs")
    Ant.copy(file:"${pluginBasedir}/src/samples/SamplePluginConfiguration.groovy",
             todir:"${basedir}/grails-app/conf")// To access Grails home you can use following code:
    // Ant.property(environment:"env")
    // grailsHome = Ant.antProject.properties."env.GRAILS_HOME"

#### Scripting events

It is also possible to hook into command line scripting events through plug-ins. These are events triggered during execution of Grails target and plugin scripts.

For example, you can hook into status update output (i.e. "Tests passed", "Server running") and the creation of files or artefacts.

A plug-in merely has to provide an `_Events.groovy` script to listen to the required events. Refer the documentation on Hooking into Events for further information.