Last updatedDec 14, 2017

Hosting events

Overview

Bitbucket Server provides events which can be used to hook into SCM hosting operations. Of particular interest for hosting are the push event and the pull event.

Using Bitbucket Server events you can respond to user operations which repository hooks cannot. You can also replicate the behavior of global hooks.

Example: using an event to replicate global hooks

MyBitbucketEventListener.java

1
2
3
4
5
6
7
8
9
10
11
12
13
package com.atlassian.bitbucket.example;

import com.atlassian.event.api.EventListener;

public class MyBitbucketEventListener 
{
    @EventListener
    public void mylistener(RepositoryPushEvent pushEvent) 
    {
        // call to your psuedo-hook with pushEvent.getRepository() 
	// and pushEvent.getRefChanges()
    }
}

Note: you won't be able to reject a push or write information back to the client using this method.

Some examples of where we use these events in Bitbucket Server:

  • In pull requests, to work out if we need to update a pull request based on a client's push.
  • In branch permissions, to work out if we can delete a branch permission (when the branch is deleted).

Responding to application events is detailed here.