Recently, I want to update my company's site using program to automatic update the issue status, adding comments, etc.
I could use JIRA Web service SOAP/XML-RPC to access, like Jenkins JIRA plugin, but according to the JIRA document about remote API reference, the REST API is recommended and supported.
so I decide to use JIRA REST API. I did some research, there are some possible options:
- Use JIRA Java Client library;
- Use Groovy HttpBuilder
For JIRA java client library, I get stuck with the maven, it always gives me error, and I was scared by its depencency on so many libraries.And For Groovy HttpBuilder, I have the same feeling, it depends on many 3rd party libraries.
So I decide to choose the 3rd solution. Just use Java HttpConnection object inside the Groovy script, and finally I got it works, it didn't use too many lines of codes, and Groovy 1.8 built-in support JSON parser, which is very handy.
Here I posted two groovy samples, you can easily integrate them into your own JIRA site by adding the url and account information.
Request an JIRA issue
JIRA add comment
Note:
Note:1. JIRA URL should be like this:
http://hostname/rest/api/2/issue/MKY-1
2. According to JIRA reference: The prefered authentication methods are HTTP Basic (when using SSL) and OAuth, in Groovy code
...
def authString = "user_id:password".getBytes().encodeBase64().toString()
conn.setRequestProperty( "Authorization", "Basic ${authString}" )
Useful resource
JIRA REST API reference
JIRA REST API Version 2 Tutorial
Fantastic :) You are a genius!
ReplyDeleteGreat!
ReplyDeleteExactly what I am loolking for.
Thanks a lot!
Very cool. I am actually trying to CREATE an issue. Any sample code on doing this?
ReplyDeleteThanks
Sorry I don't have it right now, but I don't think it is too hard to use JIRA REST API
ReplyDeleteYea, Ive been trying to figure out how to do it but have not been getting too far. If you happen to try it, please let me know.
DeleteThanks!
I've done that :) Just read the documentation. It's all there.
DeleteHow can we call post method
ReplyDeleteconn.setRequestMethod("POST");
DeleteI like to read your blog. You shared a wonderful information.
ReplyDeleteJira Training
Very nice information provided by th author. Read about OKR and it's need here.
ReplyDeleteNice blogg
ReplyDelete