I’m a big believer in learning by example. When I’m about to start working with a new library or piece of technology, I first look for prior art to demonstrate the common patterns and idioms associated with its use. For Atlassian plugins, this used to involve trawling through Bitbucket for decent examples or downloading plugin source jars from maven and browsing through them. But there is an easier way! The Atlassian SDK ships with a set of interactive scripts for creating a plugin and customising it to suit your requirements. Step 0: Generating a plugin project The first step is installing the Atlassian SDK or, if you already have it installed, upgrading to a recent version using the atlas-update command. Then, invoking the atlas-create-stash-plugin and following the prompts will create you a shiny new Stash plugin project, in a ready-to-build-and-deploy state. 12345678910$ atlas-create-stash-plugin ... [INFO] [stash:create] Define value for groupId: : com.mycompany.stash.plugin Define value for artifactId: : my-fun-plugin Define value for version: [1.0-SNAPSHOT]: Define value for package: [com.mycompany.stash.plugin]: ... $ ls my-fun-plugin/ LICENSE README pom.xml src At this point, you can start up Stash with your new plugin installed by invoking the atlas-run command. But our plugin (though deployable) doesn’t do anything useful yet. Step 1: Generating customized plugin modules The SDK ships with a second set of commands that allow you to customize your plugin with the various plugin modules supported by Stash. From the newly created plugin directory, running atlas-create-stash-plugin-module will present you with a list of Stash plugin module types: 1234567891011121314151617181920212223242526$ atlas-create-stash-plugin-module ... [INFO] [stash:create-plugin-module] Choose Plugin Module: 1: Changeset Indexer 2: Component Import 3: Component 4: Downloadable Plugin Resource 5: Licensing API Support 6: Module Type 7: REST Plugin Module 8: Repository Hook 9: SCM Request Check 10: Servlet Context Listener 11: Servlet Context Parameter 12: Servlet Filter 13: Servlet 14: SSH Request Handler 15: Keyboard Shortcut 16: Template Context Item 17: Web Item 18: Web Panel Renderer 19: Web Resource 20: Web Resource Transformer Choose a number (1/2/3/4/5/6/7/8/9/10/11/12/13/14/15/16/17/18/19/20): (if you don’t see the full list above, try running atlas-update to make sure you’re on the latest version of the SDK) For this example we’ll take a look at option 8, the Repository Hook plugin module that shipped in Stash 2.2. To make things more interesting, let’s create a hook that solves a real problem. Atlassian has a bit of a reputation for enjoying a beer or two. Let’s create a hook that confiscates the metaphorical keys from a developer’s IDE after “Beer O’Clock”. That is, prevent pushes to a repository’s master branch after 5pm on a Friday. Once you’ve selected option 8 (Repository Hook) you’ll be greeted with another interactive prompt that will ask you some simple questions to customize your new plugin module: 123456789101112131415Choose a number (1/2/3/4/5/6/7/8/9/10/11/12/13/14/15/16/17/18/19/20): 8 Enter New Classname [MyRepositoryHook]: BeerOClockHook Enter Package Name [com.atlassian.stash.plugin.hook]: Enter Hook Type (pre/post/merge) [post]: pre Show Advanced Setup? (Y/y/N/n) [N]: N [INFO] Adding the following items to the project: [INFO] [class: ccom.atlassian.stash.plugin.hook.BeerOClockHook] [INFO] [dependency: org.mockito:mockito-all] [INFO] [...]