I’m going to show you how to create a simple Atlassian Plugin, using the Application Links API. The plugin will be a Jira Custom Field.


Create the custom field

See here for specifics. Your atlassian-plugin.xml should end up looking something like this:
[cc lang=”xml”] xmlns=”http://www.atlassian.com/schema/plugins”


A field for referencing issues from another Jira server.


Component import

We need to get a reference to the API services, so that we can invoke them. I’m going to use the EntityLinkService, to link to projects on other Jira servers. Add the following to atlassian-plugin.xml:

[cc lang=”xml”][/cc]

If you want to learn more about Component Import plugin modules, see here.

The code

The external issue field is basically a text field, so I can reuse some functionality by extending the StringCFType class. Since we have the component import of the EntityLinkService, it will get automatically injected if we have it as a constructor parameter.

[cc lang=”java”]
public class ExternalIssueField extends StringCFType
private final EntityLinkService entityLinkService;

public ExternalIssueField(final CustomFieldValuePersister customFieldValuePersister, final GenericConfigManager genericConfigManager, final EntityLinkService entityLinkService)
super(customFieldValuePersister, genericConfigManager);
this.entityLinkService = entityLinkService;

Now we can use the EntityLinkService to pass information to the UI. Overriding the getVelocityParameters() method allows us to pass values to the velocity macros for viewing and editing the field.

[cc lang=”java”]@Override
public Map getVelocityParameters(final Issue issue, final CustomField field, final FieldLayoutItem fieldLayoutItem)
final Map result = super.getVelocityParameters(issue, field, fieldLayoutItem);

final EntityLink link = entityLinkService.getPrimaryEntityLink(issue.getProjectObject(), JiraProjectEntityType.class);
final boolean hasLink = link != null
result.put(“hasLink”, hasLink);
if (hasLink)
result.put(“linkName”, link.getName());
result.put(“projectLinkUrl”, link.getDisplayUrl());
result.put(“appLinkUrl”, link.getApplicationLink().getDisplayUrl());
result.put(“linkedProjectKey”, link.getKey());
return result;

The velocity macros

For the view, edit and xml macros, I used the basic text macros from the Jira codebase as a starting point.


[cc lang=”java”]#if ($value)
#if (${displayParameters.excel_view})
$textutils.br($textutils.htmlEncode($!value.toString(), false))
#if ($hasLink == true)

This creates a hyperlink to the Jira issue on the external server.


[cc lang=”java”]#customControlHeader ($action $customField.id $customField.name $fieldLayoutItem.required $displayParameters $auiparams)
#if ($hasLink == false)

No link to another Jira server!


Enter an issue key for $linkName:

#customControlFooter ($action $customField.id $fieldLayoutItem.fieldDescription $displayParameters $auiparams)[/cc]

This creates a hyperlink to the Jira project on the external server.


[cc lang=”java”]#if($renderedValue)
#elseif ($value)


This is unchanged from xml-basictext.vm.

How to use the plugin

First, there needs to be an Application Link to another Jira server, and a Project Link to a project on the linked Jira server. See here for details.

Next, we want to add a custom field, so that we can see the fruits of our work. Select the field type that we created in the plugin:


Enter a name and description:


Decide which screens to make the field visible:


Now we are going to create a new issue, and the external issue field will be there. Simply enter the Jira key for an issue on the external Jira server. Notice the hyperlink to the linked project.


Once the issue is created, the external issue field is shown when viewing the issue. Notice the hyperlink to the issue on the external server.


There you have it folks! There are plenty of ways to improve this simple example, such as UI validation or auto-completion.

Enhanced by Zemanta

A Simple Jira Plugin Using UAL...