Using repository hooks

Redirection notice

This page will redirect to /display/BitbucketServer/Using+repository+hooks .

Hooks in Stash provide a way to customise a team's workflow and integrate with other systems. Stash currently supports two types of hooks, pre and post-receive

On this page:

Managing hooks

Administrators can see the hooks that are available in Stash by going to Settings > Hooks for a Stash repository. Once installed, hooks are available across all repositories in a Stash instance, but are enabled separately on each repository in a project. 


Click the 'pen' icon beside the name of a hook to edit configuration details for the hook.

Stash currently ships with the following hooks:

  • Reject Force Push – block all Git force pushes (git push -- force).
  • HipChat Push Notifications – send a message to a HipChat room when someone pushes to the repository.

Pre-receive hooks

The first hook to run when handling a push from a client is the pre-receive hook. It can reject pushes to the repository if certain conditions are not fulfilled. You can use this hook to prevent force pushes to the repository or check whether all commits contain a valid JIRA issue key.  

Post-receive hooks

The post-receive hook runs after the commits have been processed and can be used to update other services or notify users. For example this post-receive hook could be used to send a message to a chat server or notify a continuous integration server such as Atlassian Bamboo of the newly pushed changes.

Stash supports two types of post-receive hook:

Note that a Git PostReceiveHook won't be triggered after a pull request merge. The mechanism that performs the pull request merge is actually based on a git fetch into the repository, which doesn't trigger Git post-receive hooks. To trigger functionality based on a pull request merge, you should write an AsyncPostReceiveRepositoryHook for the Stash repository.

Getting hooks from the Atlassian Marketplace

A number of hooks are available from the Atlassian Marketplace. You can find and install these from within Stash – simply use the Add hook button on the hooks settings page to view available hooks from the marketplace. See Managing add-ons for details.

Creating your own hooks

Developers can write receive hook plugins for Stash using a simple API that provides a simple way to create a configuration interface, and stores the hook's configuration settings on a per-repository basis. 

For information about how to write your own hooks please see the Stash developer docs.

In particular, these pages will be helpful:

See too this blog post about hooks for Stash: http://blogs.atlassian.com/2013/03/stash-git-hooks-api/

For a quick video demo on how to get started on Stash hooks: https://developer.atlassian.com/blog/2015/01/beer-o-clock-stash-plugin-tutorial/

Was this helpful?

Thanks for your feedback!

Why was this unhelpful?

Have a question about this article?

See questions about this article

Powered by Confluence and Scroll Viewport