Rate this page:
Deprecated in 5.0
The pre-receive module type has been deprecated in Bitbucket Server 5.0 and will be removed in 6.0. Please use the repository-hook module type instead. More details can be found in the Repository Hooks and Merge Checks Guide
Pre-receive hooks are used to potentially block pushes to Bitbucket Server. An example might be to stop deletion of branches or restrict force-pushes to personal branches.
Note This hook module is enabled across all repositories. Please see the guide on creating repository hooks.
Name | Required | Description | Default |
---|---|---|---|
key | Yes | The identifier of the plugin module. This key must be unique within the plugin where it is defined. | N/A |
class | Yes | The fully qualified Java class name of the hook. This class must implement com.atlassian.bitbucket.hook.PreReceiveHook . | 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 |
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 |
Here is an example atlassian-plugin.xml
file containing a single merge check:
1 2<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> <pre-receive-hook key="myPreReceiveHook" name="Show some example" class="com.mycompany.example.plugin.myhook.MyPreReceiveHook"> <description>A pre-receive hook example that disables deleting of branches</description> </pre-receive-hook> </atlassian-plugin>
And the corresponding hook:
1 2package com.mycompany.example.plugin.myhook; import com.atlassian.bitbucket.hook.HookResponse; import com.atlassian.bitbucket.hook.PreReceiveHook; import com.atlassian.bitbucket.repository.RefChange; import com.atlassian.bitbucket.repository.RefChangeType; public class MyPreReceiveHook implements PreReceiveHook { /** * Disables deletion of all branches. */ @Override public boolean onReceive(Repository repository, Collection<RefChange> refChanges, HookResponse hookResponse) { for (RefChange refChange : refChanges) { if (refChange.getType() == RefChangeType.DELETE) { return false; } } return true; } }
Rate this page: