JIRA Scripting API

Version 24.33 by Vincent Massol on 2016/05/29 19:29

cogProvides scripting access to JIRA using JIRA's Client API (JRJC)
TypeJAR
CategoryAPI
Developed by

Vincent Massol, XWiki Development Team

Rating
0 Votes
LicenseGNU Lesser General Public License 2.1
Compatibility
  • Version 7.1.1/7.2M2/6.4.4: Needs XWiki 3.2+ and JIRA Server 4.2 - 4.4.5 (doesn't work with JIRA versions >= 5.x).
  • Version 7.1.2/7.2M3/6.4.5: Added support for JIRA Server 4.5+

Installable with the Extension Manager

Description

This module exposes the JRJC API to XWiki scripts. JRJC is a Java library to easily access a JIRA instance (Internally it uses the JIRA REST API).

Note that if you wish to use Groovy scripting then it would be easier to simply use directly the JIRA REST API (thanks to Groovy super powerful JSON slurper). If you wish to use Velocity or other scripting languages this module might be more useful to you since those other scripting languages may not have an easy way to parse a JSON response.

Examples

Check also the JRJC Tutorial and JRJC Javadoc.

Example without being authenticated

Velocity:

{{velocity}}
#set ($client = $services.jira.getJiraRestClient("http://jira.xwiki.org/"))
#set ($pm = $services.jira.getNullProgressMonitor())
#set ($issue = $client.getIssueClient().getIssue("XWIKI-1000", $pm))

Summary: $issue.summary
{{/velocity}}

Groovy:

{{groovy}}
import com.atlassian.jira.rest.client.*

def client = services.get("jira").getJiraRestClient("http://jira.xwiki.org/")
def pm = new NullProgressMonitor();
def issue = client.getIssueClient().getIssue("XWIKI-1000", pm);

println "Summary: ${issue.getSummary()}"
{{/groovy}}

Example with Authentication

From the JRJC documentation:

 Currently JRJC fully supports only Basic HTTP authentication (other means are coming soon), which means that you should not use it in public networks without encryption as your credentials more or less travel in the open text (just encoded with Base64). Thus use HTTPS to talk to your JIRA whenever possible. Use HTTP only in internal, private networks or for tests.

Velocity:

{{velocity}}
#set ($client = $services.jira.getJiraRestClient("http://jira.xwiki.org/", "username", "password"))
...
{{/velocity}}

Groovy:

{{groovy}}
...
def client = services.get("jira").getJiraRestClient("http://jira.xwiki.org/", "username", "password")
...
{{/groovy}}

Example to find all issues matching a JQL query

Velocity:

{{velocity}}
#set ($client = $services.jira.getJiraRestClient("http://jira.xwiki.org/"))
#set ($pm = $services.jira.getNullProgressMonitor())

|=Key
#foreach ($basicIssue in $client.getSearchClient().searchJql("project = XWIKI AND status = Closed and fixVersion in ('3.2 M1', '3.2 M2', '3.2 M3', '3.2 RC1', '3.2') ORDER BY priority DESC", $pm).getIssues())
 |$basicIssue.getKey()
#end
{{/velocity}}

Groovy:

{{groovy}}
import com.atlassian.jira.rest.client.*
import com.atlassian.jira.rest.client.domain.*

def client = services.get("jira").getJiraRestClient("http://jira.xwiki.org/")
def pm = new NullProgressMonitor()
def issueClient = client.getIssueClient()

println "|=Key"
client.getSearchClient().searchJql("project = XWIKI AND status = Closed and fixVersion in ('3.2 M1', '3.2 M2', '3.2 M3', '3.2 RC1', '3.2') ORDER BY priority DESC", pm).getIssues().each() { basicIssue ->
  println "|${basicIssue.getKey()}"
}
{{/groovy}}

Prerequisites & Installation Instructions

We recommend using the Extension Manager to install this extension (Make sure that the text "Installable with the Extension Manager" is displayed at the top right location on this page to know if this extension can be installed with the Extension Manager).

You can also use the manual method which involves dropping the JAR file and all its dependencies into the WEB-INF/lib folder and restarting XWiki.

Dependencies

Dependencies for this extension (org.xwiki.contrib.jira:jira-api 8.2):

Get Connected