How to write a simple plugin that adds a new tab in JIRA

How to write a simple plugin that adds a new tab (section) to JIRA’s top-level menu, with a number of menu items in the section. The menu items link to specific web pages. 

You can use this sort of plugin to add links from JIRA to other locations in your environment, such as your company’s intranet or your Confluence site.

In order to do this, you will create a JIRA plugin consisting of the following components:

[list_icon color=”blue” type=”icon_arrow”]

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

[/list_icon]

Step 1. Create the Plugin Project

Use the appropriate atlas-create-application-plugin command to create your plugin. For example, atlas-create-jira-plugin or atlas-create-confluence-plugin.
[list_icon color=”blue” type=”icon_arrow”]

  • Follow the instructions in the above SDK documents to set up your plugin development environment.
  • Follow the instructions in the above SDK documents to run atlas-create-jira-plugin. This will create your skeleton plugin. You will be prompted for some information to identify your plugin. Enter the following information:

group-id: com.infowarestudios.plugins.MaintainSLA
artifact-id: jira-MaintainSLAMene-items
version: 1.0
package: com.infowarestudios.plugins.MaintainSLA

[/list_icon]

When the script finishes, open your new local instance of JIRA in your browser at http://localhost:2990/jira.

Your plugin skeleton is already installed and running in JIRA. Take a look at it now, by following these steps:
[list_icon color=”blue” type=”icon_arrow”]

  • Click the downward-pointing arrow next to ‘Administration‘ in JIRA’s top menu bar.
  • Select ‘Plugins‘ from the dropdown list.
  • The ‘Current Plugins’ page opens. Search for ‘jira-menu-items‘ and click the link.

[/list_icon]
The detail for the plugin will appear

Step 2. Add Plugin Metadata to the POM

Now you need to edit your POM (Project Object Model definition file) to add some metadata about your plugin and your company or organisation.
[list_icon color=”blue” type=”icon_arrow”]

  • Edit the pom.xml file in the root folder of your plugin.
  • Add your company or organisation name and your website to the <organization> element:
<organization>    <name>Infoware Studios</name>    <url>http://infowarestudio.co.za/</url></organization>
  • Update the <description> element:
<description>This plugin adds a new section and items to JIRA's menu</description>
  • Save the file.

[/list_icon]

Step 3. Register the Plugin Modules in the Plugin Descriptor

Next you will add the required plugin modules to your plugin descriptor at src/main/resources/atlassian-plugin.xml. The plugin descriptor is an XML file that identifies the plugin to JIRA and defines the functionality that the plugin requires.

Here’s a basic plugin descriptor:

<atlassian-pluginkey="${project.groupId}.${project.artifactId}"name="${project.artifactId}"plugins-version="2">    

<plugin-info>

        <description>${project.description}</description>

        <version>${project.version}</version>

        <vendorname="${project.organization.name}"url="${project.organization.url}"/>

    </plugin-info>

</atlassian-plugin>

Note that some of the information from the POM is transferred to the plugin descriptor using variable names such as${project.artifactId}.

You will need the following plugin modules:

[list_icon color=”blue” type=”icon_arrow”]

  • 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.

[/list_icon]

Follow these instructions to add the new section and menu items:

[list_icon color=”blue” type=”icon_arrow”]

  • Edit your plugin descriptor at src/main/resources/atlassian-plugin.xml.
  • Add the following web section into your plugin descriptor. This defines the top-level section where we will put all our menu items and links:
<web-sectionkey="my_links_section"name="My Links MainSection”location=”my_links_link”weight=”10″/>
  • 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.
  • 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:
<web-itemkey="my_links_link"name="Link on My Links MainSection”section=”system.top.navigation.bar”weight=”47″>    <label>Maintanance</label>

    <linklinkId="my_links_link">http://www.atlassian.com</link></web-item>

  •  The linkId is optional, and provides an XML id for the link being generated.
  • Add another web item, to create a single menu item with text ‘Web Site’ that links to your company website.
<web-item key="website_link" name="my client" section="my_links_link/my_links_section" weight="10"><label>Client details</label><link linkId="website_link">http://localhost:8084/MaintainClient/</link></web-item>
  • Add another web item, to create a menu item with text ‘Documentation’ that links to your documentation website.
<web-item key="documentation_link" name="my SLA" section="my_links_link/my_links_section" weight="10"><label>SLA</label><link linkId="documentation_link">http://localhost:8084/MaintainSLA/</link></web-item>
  • Save the file.

[/list_icon]

Here’s what your atlassian-plugin.xml file looks like now:

<atlassian-plugin key="${project.groupId}.${project.artifactId}" name="${project.name}" plugins-version="2"><plugin-info>

<description>${project.description}</description>

<version>${project.version}</version>

<vendor name="${project.organization.name}" url="${project.organization.url}" />

<param name="plugin-icon">images/pluginIcon.png</param>

<param name="plugin-logo">images/pluginLogo.png</param>

</plugin-info>

     

      <web-section key="my_links_section" name="My Links Main Section" location="my_links_link" weight="10"/>

 

<web-item key="my_links_link" name="Link on My Links Main Section" section="system.top.navigation.bar" weight="47">

<label>Maintainance</label>

 

</web-item>

 

<web-item key="website_link" name="my client" section="my_links_link/my_links_section" weight="10">

<label>Client details</label>

<link linkId="website_link">http://localhost:8084/MaintainClient/</link>

</web-item>

 

<web-item key="documentation_link" name="my SLA" section="my_links_link/my_links_section" weight="10">

<label>SLA</label>

<link linkId="documentation_link">http://localhost:8084/MaintainSLA/</link>

</web-item>

 

      <web-item key="documentation_link" name="Line of Business" section="my_links_link/my_links_section" weight="10">

<label>Line of Business</label>

<link linkId="documentation_link">http://localhost:8084/MaintainLOB/ </link>

</web-item>

 

<web-item key="documentation_link" name="Application" section="my_links_link/my_links_section" weight="10">

<label>Application</label>

<link linkId="documentation_link">http://localhost:8084/MaintainApplication/ </link>

</web-item>

 

      <web-item key="documentation_link" name="Root Cause" section="my_links_link/my_links_section" weight="10">

<label>Root Cause</label>

<link linkId="documentation_link">http://localhost:8084/MaintainRootCause/ </link>

</web-item>

</atlassian-plugin>

Step 4. Build, Install and Run the Plugin

Follow these steps to build and install your plugin, so that you can test your code. If you have not already started the application, start it now:

[list_icon color=”blue” type=”icon_arrow”]

  • Open a command window and go to the plugin root folder (where the pom.xml is located).
  • Run atlas-run (or atlas-debug if you might want to launch the debugger in your IDE).

[/list_icon]


BY: SOFTWARE DEVELOPER AT INFOWARE STUDIOS


Enhanced by Zemanta

Interesting Infoware Studios Bookmarks

0
  Related Posts