Setting up a repository hook with JSON
To use the notification hook in Notifyr a JSON configuration must be added to the root of your source code. The advantage of having a JSON file that is part of your source code is that:
- You can include a default setting in your project architecture.
- Developers can include their own notification if required
- Much more flexibility on the type of notifications based on branches
Prepare your repository for the notification hook
For a repository to use the notification hook, a JSON file named
notifications.json needs to be added to the root of the repository. A bare minimum
notifications.json file would look like this:
The above configuration would send a notification to
[email protected] for every push made to the repository.
The JSON configuration has more options and flexibility in when to send what kind of notification and to who. Take the following configuration for example:
There are a few things happening here, but the first thing you might notice is that you are able to specify multiple rules. Let's explain the options
|match||An Ant-based pattern to match your branch against|
An Ant-based pattern to match your file paths against
An array of events on which the rule should be triggered. Possible events are
an array of notifications:
Enable to Notification Hook
Repository administrators can setup the hooks that are available in Bitbucket by going to Settings > Hooks for a Bitbucket repository. Once installed, hooks are available across all repositories in a Bitbucketinstance, but are enabled separately on each repository in a project.
To setup the Notification Hook:
- Browse to the Hooks overview in your repository settings
- Browse to the relevant repository
- Choose Settings from the repository navigation
- Select Hooks from the left menu
- Toggle the Notifyr - Notification Hook setting to Enabled.