JIRA Scripting API

Last modified by Vincent Massol on 2024/08/26 00:02

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

Vincent Massol, XWiki Development Team

Active Installs2
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("<jira configuration id>"))
#set ($pm = $services.jira.getNullProgressMonitor())
#set ($issue = $client.getIssueClient().getIssue("XWIKI-1000", $pm))

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

Note that in order to define a <jira configuration id> you'll need to install and use the JIRA Administration application.

Groovy:

{{groovy}}
import com.atlassian.jira.rest.client.*
import org.xwiki.contrib.jira.config.*

def client = services.get("jira").getJiraRestClient(new JIRAServer("https://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("<jira configuration id>"))
...
{{/velocity}}

Groovy:

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

Example to find all issues matching a JQL query

Velocity:

{{velocity}}
#set ($client = $services.jira.getJiraRestClient("<jira configuration id>"))
#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(new JIRAServer("https://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.


If you're installing XWiki 7.x or in some XWiki 8.x versions (< 8.2M1), you'll find that the Extension Manager will raise en error about some incompatibility with some bundled core Extensions. To work around them follow these instructions.

Dependencies

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

  • org.xwiki.contrib.jira:jira-config-api 9.0
  • org.xwiki.commons:xwiki-commons-script 14.10.20
  • org.xwiki.commons:xwiki-commons-properties 14.10.20
  • com.google.guava:guava 31.1-jre
  • com.google.errorprone:error_prone_annotations 2.16
  • org.checkerframework:checker-qual 3.27.0
  • com.atlassian.jira:jira-rest-java-client-app 5.2.7
  • jakarta.xml.bind:jakarta.xml.bind-api 2.3.3
  • org.glassfish.jaxb:jaxb-runtime 2.3.7
  • org.xwiki.commons:xwiki-commons-tool-test-component 14.10.20

Get Connected