Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How do I access jira rest api from within bamboo task plugin?

Casey Harford January 6, 2013

What is the best way to access the jira rest api, from within the Bamboo task plugin? I have an application link setup, but when I try to use something like:

input = new URL(url + "/rest/api/latest/search/?jql=" + jql).openStream();
			reader = new InputStreamReader(input, "UTF-8");
	   		data = new Gson().fromJson(reader, JiraData.class);

There's authentication issues. What's the best method to handle something like this? I'm trying to create an issue through the rest api. I have been able to create an issue through the rest api using just a regular shell script, with basic authentication, but in this case, i'm trying to use the application link authorization in Bamboo.

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Answer accepted
PiotrA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 7, 2013

Hey Casey,

Maybe you could use http://docs.atlassian.com/bamboo/4.3/com/atlassian/bamboo/jira/rest/JiraRestService.html to do that? You would need to inject the JiraRestService into your task somehow, and pass there ApplicationLink to your JIRA as well. Then you could execute something like:

JiraRestResponse response = jiraRestService.doRestCallViaApplink(applicationLink, "rest/api/latest/search/?jql="+jql, GET, null);
data = new Gson().fromJson(wrapIntoReader(response.body), JiraData.class);

I think to retrieve the list of app-linked JIRAs you can use http://docs.atlassian.com/bamboo/4.3/com/atlassian/bamboo/applinks/JiraApplinksService.html

Is that helpful?

Casey Harford January 7, 2013

According to the pom.xml, it's 4.2.2. I noticed the api link you sent is for 4.3. I tried updating the pom, but it can't find the updated version in the sdk repo.

Here's the relevant portion of my pom.xml:

...

<properties>

<bamboo.version>3.2.2</bamboo.version>

<bamboo.data.version>3.2.2</bamboo.data.version>

<amps.version>4.1.2</amps.version>

</properties>

...

<dependency>

<groupId>com.atlassian.bamboo</groupId>

<artifactId>atlassian-bamboo-web</artifactId>

<version>${bamboo.version}</version>

<scope>provided</scope>

</dependency>

...

Casey Harford January 7, 2013

Hi Piotr,

Thank you very much, that info looks to be exactly what I need. However, i'm having a dependency issue. I can't get the JiraRestService import to work. I'm using something like:

import com.atlassian.bamboo.jira.rest.JiraRestService;

But it is unresolved. Any ideas?

PiotrA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 7, 2013

Which Bamboo version are you writing your task plugin against?

Casey Harford January 7, 2013

In line 2 of your example, where does the wrapIntoReader method come from?

Casey Harford January 7, 2013

I just answererd my question myself. Looks like I was actually using 3.2.2 Ha, I changed it to 4.2.2, and did atlas-mvn eclipse:eclipse, and now the dependency is resolved. Thanks for your help.

PiotrA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 7, 2013

...........

PiotrA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 7, 2013

You must write it. I assume that you want to convert the response from JIRA into some JiraData class (I don't know what that is). So probably you will need to convert+adjust JiraRestReponse.body (which is String I presume) into some StreamInputReader, or Json object - dunno. But I'm pretty sure that you will manage to figure that out. :)

Casey Harford January 7, 2013

Ok that makes sense. I'm now having issues running the plugin in Bamboo. In eclipse, the import shows as valid, there arn't any errors. But when I try to install plugin into bamboo, I get an error about a unique bean not being found for the JiraRestService. I tried adding a component-import to my atlassian-plugin.xml, but that did not resolve the issue. I have the following in my atlassian xml file:

<component-import key="jira-rest-service" name="Jira Rest Service" interface="com.atlassian.bamboo.jira.rest.JiraRestService">

<description>Jira rest service stuff</description>

</component-import>

With the above in my xml, it still doesn't work. Instead it gives me the error:

[OsgiPlugin] Never resolved service '&jira-rest-service' for plugin 'com.build.bamboo.plugins.VeracodePlugin' with filter (objectClass=com.atlassian.bamboo.jira.rest.JiraRestService)

Any ideas why this wouldn't work?

PiotrA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 8, 2013

Which "pluginsVersion" are you using? 2? (in atlassian-plugin.xml) If so, can you temporarily switch to 1? (note: that way you would have to restart Bamboo to install that plugin).

I'm thinking that maybe we didn't expose yet the JiraRestService to the plugins of version 2...

Casey Harford January 8, 2013

I tried changing the version to 1, and then did an "atlas-clean" followed by atlas-run, and ended up with several stack traces, resulting in Bamboo not being able to start. Switching back the verison, and running the atlas-clean + atlas-run, enabled Bamboo to run again.

I'm wondering how the Jira Plugin that ships with Bamboo handles this. Any idea where the source is for that?

PiotrA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 9, 2013

I think the bamboo-to-jira integration code is shipped together with Bamboo source. Do you have access to it? AFAK it comes with the more expensive licenses...

Yann Augustin January 29, 2013

Hello,

I am new in Bamboo plugin dev and I can not figure our how I can get the "applicationLink".

How do we use the JiraApplinksService ?

Best regards

PiotrA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 30, 2013

Hi Yann,

What are you trying to achieve?

Actually I think it could be a better idea to raise a new question here on answers.atlassian.com, than trying to continue discussion here via comments... wouldn't it?

cheers,

Yann Augustin January 30, 2013

Ok sorry.

I will create a new question.

Best regards

PiotrA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 30, 2013

No problem. Just remember to mark it with bamboo-plugin-development tag :)

0 votes
Casey Harford January 9, 2013

Yes, I have acces. I will take a look. Thank you for your help!

PiotrA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 9, 2013

CreateNewJiraIssueAction.java might be a good starting point for you then.

TAGS
AUG Leaders

Atlassian Community Events