Post-Receive Hook Plugin Module

Introduction

Post-receive hooks are similar to pre-receive-hooks except that the push cannot be cancelled. They are useful for outputting messages to the client. If no message is required consider listening for RepositoryPushEvent instead.

Note This hook module is enabled across all repositories. Please see the guide on creating repository hooks.

Configuration

Attributes

Name Required Description Default
key The identifier of the plugin module. This key must be unique within the plugin where it is defined. N/A
class The fully qualified Java class name of the hook. This class must implement com.atlassian.bitbucket.hook.PostReceiveHook. N/A
name The human-readable name of the plugin module. I.e. the human-readable name of the hook. N/A
weight The (integer) weight of the plugin module. Hooks with a higher weight will be processed later. It should almost never be necessary to set this. Your hook implementation should not rely on a particular order for it to function correctly as the absolute ordering also depends on the weight set on other hooks. 1000

Elements

Name Required Description Default
description The description of the plugin module. The 'key' attribute can be specified to declare a localisation key for the value instead of text in the element body. I.e. the description of the servlet. N/A

Example

Here is an example atlassian-plugin.xml file containing a single merge check:

<atlassian-plugin name="My Merge Request Check" key="example.plugin.preceive" plugins-version="2">
    <plugin-info>
        <description>A basic component import module test</description>
        <vendor name="My Company" url="http://www.mycompany.com"/>
        <version>1.0</version>
    </plugin-info>

    <post-receive-hook key="myPostReceiveHook" name="Show some example" class="com.mycompany.example.plugin.myhook.MyPostReceiveHook">
        <description>A post-receive hook example that thanks the user for pushing</description>
    </post-receive-hook>
</atlassian-plugin>

And the corresponding hook:

package com.mycompany.example.plugin.myhook;

import com.atlassian.bitbucket.hook.HookResponse;
import com.atlassian.bitbucket.hook.PostReceiveHook;

public class MyPostReceiveHook implements PostReceiveHook {

    @Override
    public void onReceive(Repository repository, Collection<RefChange> refChanges, HookResponse hookResponse) {
        hookResponse.out().println("Thank you for pushing to Bitbucket Server");
    }
}