Gitblit uses Groovy for its push hook mechanism. This mechanism only executes when pushing to Gitblit, not when pushing to some other Git tooling in your stack.
The Groovy hook mechanism allows for dynamic extension of Gitblit to execute custom tasks on receiving and processing push events. The scripts run within the context of your Gitblit instance and therefore have access to Gitblit's internals at runtime.
gitblit.properties
or web.xml
.gitblit.properties
or web.xml
.Some sample scripts are included in the GO and WAR distributions to show you how you can tap into Gitblit with the provided bound variables. Additional implementation details may be specified in the header comment of these examples.
Hook contributions and improvements are welcome.
SINCE 1.0.0
Grape lets you quickly add maven repository dependencies to your Groovy hook script.
Grape (The Groovy Adaptable Packaging Engine or Groovy Advanced Packaging Engine) is the infrastructure enabling the grab() calls in Groovy, a set of classes leveraging Ivy to allow for a repository driven module system for Groovy. This allows a developer to write a script with an essentially arbitrary library requirement, and ship just the script. Grape will, at runtime, download as needed and link the named libraries and all dependencies forming a transitive closure when the script is run from existing repositories such as Ibiblio, Codehaus, and java.net.
// create and use a primitive array import org.apache.commons.collections.primitives.ArrayIntList @Grab(group='commons-primitives', module='commons-primitives', version='1.0') def createEmptyInts() { new ArrayIntList() } def ints = createEmptyInts() ints.add(0, 42) assert ints.size() == 1 assert ints.get(0) == 42
SINCE 1.0.0
Gitblit allows custom repository string fields to be defined in gitblit.properties
or web.xml
. Entry textfields are automatically created for these fields in the Edit Repository page of Gitblit and the Edit Repository dialog of the Gitblit Manager. These fields are accessible from your Groovy hook scripts as
repository.customFields.myField
This feature allows you to customize the behavior of your hook scripts without hard-coding values in the hook scripts themselves.
Pre-Receive scripts execute after the pushed objects have all been written to the Git repository but before the refs have been updated to point to these new objects.
This is the appropriate point to block a push and is how many Git tools implement branch-write permissions.
Post-Receive scripts execute after all refs have been updated.
This is the appropriate point to trigger continuous integration builds or send email notifications, etc.
Gitblit implements email notifications in sendmail.groovy which uses the Groovy Hook Script mechanism. This allows for dynamic customization of the notification process at the installation site and serves as an example push script.
In order to send email notifications on a push to Gitblit, this script must be specified somewhere in the post-receive script chain.
You may specify sendmail in one of three places:
gitblit.properties
or web.xml
, globally applied to all repositoriesGitblit does not currently support individual subscriptions to repositories; i.e. a user can not subscribe or unsubscribe from push notifications.
However, Repository Managers and Administrators can specify subscribed email addresses in one of three places:
gitblit.properties
or web.xml
, globally applied to all push-notified repositoriesAll three sources are checked and merged into a unique list of destination addresses for push notifications.
NOTE:
Care should be taken when devising your notification scheme as it relates to any VIEW restricted repositories you might have. Setting a global mailing list and activating push notifications for a VIEW restricted repository may send unwanted emails.