ScriptRunner REST Endpoint as transition Webhook

Dominik November 11, 2016

Hello,

 

I have created a Webhook Test

(Administration - System - WebHooks - create a WebHook)

http://server/rest/scriptrunner/latest/custom/doSomething

with no events

Then I have added the Webhook to a transition Post Function

(Add PostFunction -> Trigger a Webhook -> Test)

 

My REST Endpoint script

import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import groovy.json.JsonOutput
import groovy.transform.BaseScript
import javax.ws.rs.core.MultivaluedMap
import javax.ws.rs.core.Response
@BaseScript CustomEndpointDelegate delegate
doSomething(httpMethod: "GET") { MultivaluedMap queryParams, String body ->
  def flag = [
    type : 'success',
    title: "Test",
    close: 'manual',
    body : "Text"
  ]
  return Response.ok(JsonOutput.toJson(flag)).build()
}

 

But when i do the transition the WebHook isn't triggered.

The REST Endpoint works if i use the link in my browser

 

I also tried to use an event (create Sprint) in the WebHook but this didn't worked too

 

JIRA: 7.1.9

ScriptRunner: 4.3.12

 

____

 

Am I able to edit the title of the Question?

Update Question:

Actually I want to run a script, when I complete a JIRA sprint.

Because there is no way to run a Post Function for this task I created a WebHook in JIRA with the events:

JIRA Software related events

Sprint

  • created
  • deleted
  • started
  • closed

 

with the url host/rest/scriptrunner/latest/custom/doSomething

My script (test.groovy) I added to the ScriptRunner Rest Endpoint

import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import groovy.json.JsonOutput
import groovy.transform.BaseScript
import javax.ws.rs.core.MultivaluedMap
import javax.ws.rs.core.Response
@BaseScript CustomEndpointDelegate delegate
doSomething(httpMethod: "GET") { MultivaluedMap queryParams, String body ->
  log.warn ("web hook fired")
}

 

When I do an Event a Log entry is created

2016-11-15 11:25:33,168 http-nio-8080-exec-9 ERROR user 685x81016x1 hgbten 10.166.65.89 /rest/greenhopper/1.0/xboard/issue/details.json [c.s.collaborator.issue.IssueRest] java.net.MalformedURLException: no protocol: null/rest-service-fe/repositories-v1
2016-11-15 11:25:33,168 http-nio-8080-exec-9 ERROR user 685x81016x1 hgbten 10.166.65.89 /rest/greenhopper/1.0/xboard/issue/details.json [c.a.g.w.r.issue.thirdpartytabs.ThirdPartyTabModelFactory] Unable to load third party tab for com.meetme.plugins.jira.gerrit-plugin:gerrit-reviews-agile-panel
java.lang.ClassCastException

And in the Admin - Rest Endpoint there is no execution info for that time

 

I have the same Problem when I will call a WebHook as PostFunction when i do a transition.

There is no information in the Rest Endpoint execution info

I've created the PostFunction Webhook for a transition because I thought I have there the same problem as with a sprint webhook and also because I thought it is easier to test

 

I only get the log entry 

2016-11-15 11:33:23,553 http-nio-8080-exec-20 WARN user 693x81313x1 hgbten 10.166.65.89 /rest/scriptrunner/latest/custom/doSomething [c.o.scriptrunner.runner.ScriptRunnerImpl] web hook fired

when I call the Rest url directly in the browser

3 answers

1 vote
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 14, 2016

Are you sure it wasn't triggered? I tried it and it did fire... try adding a line like

log.warn ("web hook fired")

and tail your logs, and you will see it happened.

The problem is there is no way to get feedback via the UI like that. You can only use that simple format from web items, and then only when you specify the endpoint is going to display a flag.

If you just want to provide feedback, use a normal script post-function, and add:

import com.onresolve.scriptrunner.runner.util.UserMessageUtil

UserMessageUtil.success("Something happened...")
0 votes
Dominik November 15, 2016

I have found that way with the web hook also at Atlassian Answer

Trigger a script runner script on sprint events

In the first answer of @Adam Markham [Adaptavist] on Sep 23

But I don't know why my web hook isn't fired or the script doesn't run

 

But web hooks to other application do also work

(there is also one used for Jenkins)

0 votes
Dominik November 14, 2016

 

I edited my script to

import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import com.onresolve.scriptrunner.runner.util.UserMessageUtil
import groovy.json.JsonOutput
import groovy.transform.BaseScript
import javax.ws.rs.core.MultivaluedMap
import javax.ws.rs.core.Response

@BaseScript CustomEndpointDelegate delegate

doSomething(httpMethod: "GET") { MultivaluedMap queryParams, String body ->
  log.warn ("web hook fired")
  UserMessageUtil.success("Something happened...")
}

 

When I do the workflow transition I get this in the log file and the Message isn't shown

2016-11-15 09:12:43,432 http-nio-8080-exec-20 ERROR user 552x77082x1 100zbk0 10.166.65.89 /secure/AjaxIssueAction!default.jspa [c.s.collaborator.issue.IssueRest] java.net.MalformedURLException: no protocol: null/rest-service-fe/repositories-v1
2016-11-15 09:12:43,432 http-nio-8080-exec-20 WARN user 552x77082x1 100zbk0 10.166.65.89 /secure/AjaxIssueAction!default.jspa [c.a.j.i.search.util.SearchPropertiesManager] Invalid filter ID in user preferences:

 

At Administration - Add-Ons - Rest Endpoints - Execution Information

there is no execution shown for this time

 

But when I call the Rest Endpoint direct in my browser there is an execution information

image2016-11-15 9:20:36.png

 

 

 

An other question to the Message:

When I run the code in the Script Console for the Message

should I get it there?

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 14, 2016

Right, because when you are posting to the webhook it has a different http session. UserMessageUtil will only show messages from the same http session.

I didn't mean to use UserMessageUtil in an endpoint, I meant just write a custom post-function in place of the web hook, as it seems like the rest endpoint is on the same JIRA instance as the one triggering it. Is that the case? 

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 14, 2016

Why don't we take a step back and you update your question with a high-level overview of what you are trying to achieve.

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 14, 2016

Why don't we take a step back and you update your question with a high-level overview of what you are trying to achieve.

Dominik November 14, 2016

I can do that

but i actually used the transition because I wanted to run that when I complete a sprint and there I can't use a PostFunction Script

The only solution I've found to run a script is using a WebHook to the Rest Endpoint and there I had the same problem that I didn't see that sth. happend so I thought I can transfer the problem also to the transition webhook

 

And I've used the webhook for the transition because it is much easier to do an transition than always to create a sprint and complete/end it

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 14, 2016

OK, now I have a better picture. 

So ideally you would use a listener to do something on sprint end, but you can't because of https://productsupport.adaptavist.com/browse/SRJIRA-1910.

So you're workaround is to post to a web hook. Unfortunately I can't think of any way in which you could get feedback to the current user, using that method.

Dominik November 14, 2016

The feedback is an other problem

It seems to me that the Rest script isn't executed?

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 14, 2016

You don't see the log line when the sprint ends?

Dominik November 14, 2016

No

also not when i do an transition (where the rest is defined) or an other event i mentioned in the question update

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, 2016

It works fine here... double-check everything, including for any errors in your logs.

Dominik November 15, 2016

My Settings:

WebHook

image2016-11-15 15:24:55.png

image2016-11-15 15:27:20.png

image2016-11-15 15:27:40.png

Rest Endpoint

image2016-11-15 15:26:1.png

 

I have created a sprint at Backlog - Create Sprint

and in the log file I get this

image2016-11-15 15:30:25.png

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 17, 2016

And that URL is definitely correct? Those errors appear to be unrelated, seem to be from other plugins.

is doSomething configured to take a POST request? It needs to be IIRC. A screenshot of it after you click update in the REST endpoint will show us that.

Dominik November 17, 2016

What does IIRC mean?

 

Screenshot of this?

image2016-11-17 13:37:40.png

Dominik November 17, 2016

I've also created a new question webhook-not-fired, because I think the problem is not the REST script.

It seems to be the webhook which is not fired

I've changed the URL to https://requestb.in/XXX and there I also do not get any response when I do an event in JIRA

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 17, 2016

answered on the other question

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events