Best way to invoke external webservice on issue update (not webhooks)

BrianB November 4, 2015

We want JIRA to update an external app using a webservice. Unfortunately, the webhooks feature will not work as the webservice will only accept certain mapped parameters. Webhooks  sends a complete issue dump. I think SIL services or Listeners is out because we want to use JAVA to call the webservice.   Other options might be a Jelly service or Groovy script listener.

7 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
BrianB December 1, 2015

The only event that invokes the listener is Create.  We really need Issue Resolved,Closed or Issue commented to work.

 

Is there another method besides workflowEvent that we are supposed to call for these events?

public void workflowEvent(IssueEvent event) throws IOException

JamieA
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.
December 1, 2015

> throws IOException have you got the logs? So you're saying the same method works for create?

BrianB December 1, 2015

I have the atlassian-jira.log, but nothing gets written to nor any errors appear. Just silence. It is the same exact code for Create issue event which works

BrianB December 3, 2015

Any ideas why only Create event is working? Do I need to invoke another method?

0 votes
BrianB November 12, 2015

Tried writing to a file also. Do I have my groovy file in the correct place?  It is under atlassian-jira\WEB-INF\classes\com\Brian.  Some confusion because some people have said they placed it in the groovy.jar file under com.onresolve.jira.groovy

JamieA
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.
November 15, 2015

No - it needs to be in <jira.home>/scripts/com/Brian You don't normally begin a package with an uppercase letter, although I don't think it will cause a problem.

BrianB November 16, 2015

I did not see in 2.1.16 Documentation that this is the directory to use - only in later versions. when I preview the script under WEB-INF from Add Listener, I get no errors. Now when I move the groovy script to scripts/com/brian, I get "Problem loading class: com.brian.ExampleListener"

JamieA
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.
November 16, 2015

Is there any way you can upgrade to a more recent jira version?

BrianB November 16, 2015

That is not possible at the moment. Is there an issue with 2.1.16? It seems others got it to work

BrianB November 19, 2015

Jamie, is there an update. We are becoming desperate

JamieA
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.
November 19, 2015

On the old version then yes it needs to be under web-inf/classes. The old documentation is at https://jamieechlin.atlassian.net/wiki/display/GRV/Listeners. IIRC you need to enter the class name, eg com.foo.Bar

BrianB November 19, 2015

Jamie, I have done all this. My screenshots are in the other issue I created. Why isn't it doing anything?

BrianB November 19, 2015

GRV-834

JamieA
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.
November 19, 2015

try putting the listener on another event, like "create". There shd be something in the log file. Set the plugin log level to debug https://scriptrunner.adaptavist.com/latest/jira/getting-help.html#_support_requests.

BrianB November 19, 2015

yee-ha! It works for Create! Now to debug why Issue Commented does not work

0 votes
BrianB November 12, 2015

log level is debug - but I see nothing in atlassian-jira.log after I add a comment

0 votes
BrianB November 9, 2015

I should mention we are using version 2.1.16

JamieA
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.
November 9, 2015

3.0 +

BrianB November 9, 2015

Is there a way to do this with our version. We are not upgrading JIRA anytime soon

JamieA
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.
November 10, 2015

You didn't say what version of jira you have, maybe you don't need to. Even if not, you could do it with HttpClient, which is included in jira. If you give us the same curl command I can suggest the next step.

BrianB November 10, 2015

Our JIRA version is 6.1.6. I haven't worked with curl before, but I'll try and get something going here

BrianB November 11, 2015

For testing, I'm just going to invoke the REST API of another JIRA instance. curl -D- -u usern2:psswd2 -X PUT --data @jiraAPItest -H "Content-Type: application/json" http://myjirainstance.com/rest/api/2/issue/OCES-34876 { "fields": { "assignee":{"name":"cbashyb"} } } Ideally an event (issue-commented, or issue-updated) would trigger the listener

BrianB November 11, 2015

before I add my curl statement - I built a custom listener using your example. I get no errors when I preview, but do not see any log output when I update an issue. Which log does it actually write to? package com.Brian; import org.apache.log4j.Category; import com.atlassian.jira.event.issue.AbstractIssueEventListener; import com.atlassian.jira.event.issue.IssueEvent; import com.atlassian.jira.ComponentManager; import com.atlassian.jira.issue.CustomFieldManager; import com.atlassian.jira.issue.fields.CustomField; import com.atlassian.jira.issue.ModifiedValue; import com.atlassian.jira.issue.MutableIssue; import com.atlassian.jira.issue.util.DefaultIssueChangeHolder; import com.atlassian.jira.issue.util.IssueChangeHolder; public class ExampleListener extends AbstractIssueEventListener { Category log = Category.getInstance(ExampleListener.class); //log.setLevel(org.apache.log4j.Level.DEBUG); @Override //void issueUpdated(IssueEvent event) { public void workflowEvent(IssueEvent event) { log.debug ("Hi Brian -Event: ${event.getEventTypeId()} fired for ${event.issue} and caught by ExampleListener"); } }

BrianB November 11, 2015

Do we need to register Groovy scriptrunner under System => Advanced => Listeners?

JamieA
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.
November 12, 2015

that's a custom listener.. you can just write it as a script rather than a class: https://scriptrunner.adaptavist.com/latest/jira/listeners.html#_custom_listener_example It writes to <jira-home>/logs/atlassian-jira.log, but only if you have set the log level to debug.

Like Bhanu likes this
0 votes
BrianB November 9, 2015

Thanks Jamie, what versions of Scriptrunner has HttpBuilder?

0 votes
JamieA
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.
November 8, 2015

I would work out what you want to post and use curl to test it. Once done it's easy to replicate that using HttpBuilder, which is included in scriptrunner. You can create the payload using JsonBuilder, if it takes json.

0 votes
GabrielleJ
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.
November 4, 2015

For this kind of customization, I usually let a separate entity to handle it (external it) so in JIRA, the change I really need to do is to know where it is.

So If I were to do this, I will create a shell/groovy script that will be invoked during workflow transitions or listener events.

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events