JIRA Integration
Last modified by Vincent Massol on 2021/03/18 11:28
![]() | Shows different solutions to access JIRA from an XWiki instance |
Type | Snippet |
Category | |
Developed by | |
Rating | |
License | GNU Lesser General Public License 2.1 |
Table of contents
Description
There are several solutions to access data from your online JIRA server:
- Using the older Swizzle Plugin
- Using the JIRA Module which uses JIRA's JRJC API
- Using directly JIRA REST using Groovy
In addition to this you can simply use JIRA's RSS URLs as demonstrated below. Also make sure to check out the JIRA Macro which uses the JIRA RSS URLs.
Examples
Displays the summary of an issue
{{groovy}}
def url = "http://jira.xwiki.org/si/jira.issueviews:issue-xml/XWIKI-1000/XWIKI-1000.xml".toURL().text
def root = new XmlSlurper().parseText(url)
println "${root.channel.item.summary}"
{{/groovy}}
def url = "http://jira.xwiki.org/si/jira.issueviews:issue-xml/XWIKI-1000/XWIKI-1000.xml".toURL().text
def root = new XmlSlurper().parseText(url)
println "${root.channel.item.summary}"
{{/groovy}}
Displays the content of a list of issues
{{groovy}}
def jql = URLEncoder.encode("issueKey=XWIKI-1000 OR issueKey=XWIKI-1001", "UTF-8")
def columns = "field=type&field=key&field=summary&field=assignee&field=status&field=link"
def url = "http://jira.xwiki.org/sr/jira.issueviews:searchrequest-xml/temp/SearchRequest.xml?jqlQuery=${jql}&${columns}".toURL().text
def root = new XmlSlurper().parseText(url)
println "|=Type|=Id|=Summary|=Assignee|=Status"
root.channel.item.each() {
println "|[[image:${it.type.@iconUrl}]]|[[${it.key}>>${it.link}]]|${it.summary}|${it.assignee}|[[image:${it.status.@iconUrl}]]"
}
{{/groovy}}
def jql = URLEncoder.encode("issueKey=XWIKI-1000 OR issueKey=XWIKI-1001", "UTF-8")
def columns = "field=type&field=key&field=summary&field=assignee&field=status&field=link"
def url = "http://jira.xwiki.org/sr/jira.issueviews:searchrequest-xml/temp/SearchRequest.xml?jqlQuery=${jql}&${columns}".toURL().text
def root = new XmlSlurper().parseText(url)
println "|=Type|=Id|=Summary|=Assignee|=Status"
root.channel.item.each() {
println "|[[image:${it.type.@iconUrl}]]|[[${it.key}>>${it.link}]]|${it.summary}|${it.assignee}|[[image:${it.status.@iconUrl}]]"
}
{{/groovy}}
Result:
Computes total time spent
{{groovy}}
import groovy.json.*
def jql = "project = NUMPORTAL AND component = 17-002 AND component = 'Out of Scope'"
def url = "https://jira.xwikisas.com/rest/api/2/search?jql=${java.net.URLEncoder.encode(jql)}&os_username=<usernamehere>&os_password=<userpasswordhere>&os_authType=basic&field=timespent".toURL().text
def root = new JsonSlurper().parseText(url)
int totalTimespent = 0
root.issues.each() { issue ->
def spent = issue.fields.timespent
if (spent) {
totalTimespent += spent
}
}
println "Total time spent = ${totalTimespent} seconds"
{{/groovy}}
import groovy.json.*
def jql = "project = NUMPORTAL AND component = 17-002 AND component = 'Out of Scope'"
def url = "https://jira.xwikisas.com/rest/api/2/search?jql=${java.net.URLEncoder.encode(jql)}&os_username=<usernamehere>&os_password=<userpasswordhere>&os_authType=basic&field=timespent".toURL().text
def root = new JsonSlurper().parseText(url)
int totalTimespent = 0
root.issues.each() { issue ->
def spent = issue.fields.timespent
if (spent) {
totalTimespent += spent
}
}
println "Total time spent = ${totalTimespent} seconds"
{{/groovy}}