Skip to end of metadata
Go to start of metadata

Level of experience:

This is a beginner tutorial. This is a good tutorial to try if you have never developed an add-on before.

Time estimate:

It should take you approximately half an hour to complete this tutorial.

 

On this page:

Overview of the tutorial

This tutorial shows you how to write a simple plugin that adds a new menu to JIRA's header. The menu includes two menu items that link to external web pages. In terms of plugins, this is almost as simple as it gets. But it's not without its use. You can use this sort of plugin to add links to JIRA to your websites that are important for your organization, such as your company's intranet or external website.

You can add UI elements to JIRA by adding module definitions to the plugin descriptor. In this tutorial, you'll add the following modules:

  • A web section to define the new tab (section) in your JIRA top navigation bar.
  • A number of web items to add the links and menu items to the new section.

Your completed plugin will consist of the following components: 

  • A plugin descriptor to enable the plugin in JIRA.
  • The required plugin modules that define the new menu section and menu items.

Your plugin does not need any Java code because the plugin modules provided by the Atlassian Plugin Framework provide all the functionality required for this simple plugin.

Required knowledge

To complete this tutorial, you need to know the following: 

  • The basics of Java development: classes, interfaces, methods, how to use the compiler, and so on.
  • How to create an Atlassian plugin project using the Atlassian Plugin SDK.
  • The basics of using and administering JIRA.

Plugin source

We encourage you to work through this tutorial. If you want to skip ahead or check your work when you have finished, you can find the plugin source code on Atlassian Bitbucket. Bitbucket serves a public Git repository containing the tutorial's code. To clone the repository, issue the following command:

git clone https://bitbucket.org/atlassian_tutorial/jira-menu-items-plugin.git

Alternatively, you can download the source as a ZIP archive by choosing download here: https://bitbucket.org/atlassian_tutorial/jira-menu-items-plugin

Step 1. Create the plugin project

In this step, you'll use an atlas- command to generate stub code for your plugin.

  1. If you have not already set up the Atlassian Plugin SDK, do that now: Set up the Atlassian Plugin SDK and Build a Project.
  2. Open a terminal and navigate to the directory where you want to put the project home.
  3. Enter the following command to create a plugin skeleton:

    atlas-create-jira-plugin
    
  4. When prompted for the version of JIRA to target, choose 1 for JIRA 5.
  5. As prompted, enter the following information:

    group-id

    com.atlassian.plugins.tutorial

    artifact-id

    jira-menu-items

    version

    1.0-SNAPSHOT

    package

    com.atlassian.plugins.tutorial

  6. Confirm your entries when prompted.

The SDK generates the initial plugin project files in a directory named jira-menu-items.

Step 2. Review and tweak the generated stub code

It is a good idea to familiarise yourself with the project configuration file, known as the POM (Project Object Model definition file). In this section, you will review and tweak the pom.xml file. Open your plugin project in Eclipse and follow along in the next sections.

Add plugin metadata to the POM

The POM (Project Object Model definition file) is located at the root of your project and declares the project dependencies and other information.

Add some metadata about your plugin and your company or organisation.

  1. Edit the pom.xml file in the root folder of your plugin.
  2. Add your company or organisation name and your website to the <organization> element (the following code blocks show how it looks in plain text):

  3. Update the <description> element:

  4. Save the file.

Review the generated plugin descriptor

Your stub code contains a plugin descriptor file atlassian-plugin.xml. This is an XML file that identifies the plugin to the host application (JIRA) and defines the required plugin functionality. 

You should see something like this (comments removed):  

Step 3. Start JIRA

Let's start JIRA and see what we've got so far:

  1. From the command line, change to the directory created by the SDK, jira-menu-items.
  2. Enter the SDK command atlas-run.
    This starts JIRA and loads your plugin. In the output, look for a line that looks something like this.
    [INFO] jira started successfully in 134s at http://atlas-laptop:2990/jira
    It tells you that JIRA is done starting up and shows you the JIRA home page address.
  3. In a browser, open the JIRA home page address indicated in the atlas-run output. 
  4. Log in to JIRA using the default username and password combination, admin/admin.
  5. When prompted for the type of project to create, either create a project or click Cancel. JIRA prompts you to create a new project like this only when starting up a new instance.
  6. Choose Add-ons from the cog menu at the top right of the page. 
  7. Click Manage Add-ons from the left menu.
  8. In the User-installed Add-ons list, look for the plugin you created, jira-menu-items. Alternatively, type the name in the filter field to find it quickly.
  9. Click on the add-on in the list to expand its details view.
    The details of your plugin appear:

The plugin worked, but so far it doesn't do much. Let's make it add something to the JIRA UI.

Back in the command window where you started JIRA, enter Control+C to shut down JIRA for now. 

Step 4. Add the plugin modules to the plugin descriptor

Add the new section and menu items to your plugin descriptor as follows:

  1. Open the plugin descriptor for editing: src/main/resources/atlassian-plugin.xml
  2. Add the following web section as a child element to atlassian-plugin. This defines the top-level section where we will put all our menu items and links:

    The weight attribute determines the order in which web items appear. Items are displayed top to bottom or left to right in order of ascending weight. The lightest weight is displayed first, the heaviest weights sink to the bottom. The weights for most applications' system sections start from 100, and the weights for the links generally start from 10. The weight is incremented by 10 for each in sequence so that there is ample space to insert your own sections and links.

  3. Add the following web item. This defines the link on the top-level section, with text 'My Company'. We have pointed the link at the company website:

    The linkId is not optional and must be the same as the location element of the web-section. It also provides an XML id for the link being generated.

  4. Add another web item, to create a single menu item with text 'Web Site' that links to your company website.

  5. Add another web item, to create a menu item labeled "Documentation" that links to your documentation website.

  6. Save the file.

Your atlassian-plugin.xml file should look something like this:

Step 5. Restart JIRA and see your plugin in action

  1. At the command line from your plugin directory, enter atlas-run again.
  2. After JIRA starts up, log in again.
  3. Notice the new menu in the header. Clicking on the entries takes you to the URLs you entered.

Next steps

When you have finished developing and testing your plugin, you can install it into your company's JIRA instance, so that the new menu items are available for other people to use. Your plugin JAR file is at target\jira-menu-items-1.0.jar. You can install the plugin using the Universal Plugin Manager

Congratulations, that's it

Icon

Have a chocolate!

RELATED TOPICS

Web Fragments
Web Section Plugin Module
Web Item Plugin Module
JIRA Webwork Actions

2 Comments

  1. hi 

    i want to ask why when i past the jar of my menu items in my WEB-INF/lib directory i don't see all link but only My company link 

    1. Only plugins1 plugins should be installed in WEB-INF/lib.
      Plugins2 plugins get installed in "<jira-home>/plugins/installed-plugins".
      See http://confluence.atlassian.com/display/JIRA/Managing+JIRA%27s+Plugins

      This tutorial creates a plugins2 plugin.
      See the plugins-version value in the XML:

      If you change this to 'plugins-version="1"' then you would install in WEB-INF/lib.