zaterdag 24 april 2010

Using Groovy for reading your Jira database

Jira in combination with Greenhopper is a very popular tool. See this link to see a list of agile tools.

Sometimes however some additional magic and customisation is needed with your Jira issues. For this the xml-rpc interface that Jira offers can be very useful. One way to use this interface in an easy way is, of course, Groovy.

After browsing a little I found this document to be very useful. Don't forget to put the groovy xml-pc jar in your $HOME/.groovy/lib directory (more info on  Groovy-XMLRPC page). My first start is this script:

import groovy.net.xmlrpc.XMLRPCServerProxy as Proxy

def proxy = new Proxy('http://jira.codehaus.org/rpc/xmlrpc')
def loginToken = proxy.jira1.login('...','...')

def issue = proxy.jira1.getIssue(loginToken, 'GMOD-85')
issue.each{ key, value ->
    println key
}

println issue.summary
println issue.status
println issue.reporter

def user = proxy.jira1.getUser(loginToken, "ben.schreur")
println user

def projects = proxy.jira1.getProjectsNoSchemes(loginToken)
projects.each{ project ->
    println project.name
}

This is just the beginning as a will be doing some more Jira scripting on my current job. Better to automate as much as possible when going through bug-databases is needed. If you like to read more scripts on Jira just drop a comment.

Cheers!

Update March 26th: Jira does not allow access to the amount of estimated hours via xmlrpc. It does however work via soap. An update will follow. :-)

2 opmerkingen:

  1. With some 'Groovy magic' the script can be refactored to this:

    import groovy.net.xmlrpc.XMLRPCServerProxy as Proxy

    class JiraProxy extends Proxy {
    JiraProxy(url) { super(url) }
    Object invokeMethod(String methodname, args) {
    super.invokeMethod('jira1.'+methodname, args)
    }
    }


    def jira = new JiraProxy('http://jira.codehaus.org/rpc/xmlrpc')
    def loginToken = jira.login('ben.schreur','mysecret')

    def issue = jira.getIssue(loginToken, 'GMOD-85')

    issue.each{ key, value ->
    println key
    }

    println issue.summary
    println issue.status
    println issue.reporter

    println jira.getUser(loginToken, "ben.schreur")

    def projects = jira.getProjectsNoSchemes(loginToken)
    projects.each{ project ->
    println project.name
    }

    BeantwoordenVerwijderen