ScriptRunner REST Endpoint as transition Webhook

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

This widget could not be displayed.

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...")
This widget could not be displayed.

 

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?

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? 

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.

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.

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

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.

The feedback is an other problem

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

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

No

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

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

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

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.

What does IIRC mean?

 

Screenshot of this?

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

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

answered on the other question

This widget could not be displayed.

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)

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Published Jul 25, 2018 in Marketplace Apps

Jira Cloud and Bitbucket Cloud Integration with Microsoft Teams

One of the newest products in the Microsoft family - Microsoft Teams,  is a chat-based hub for teamwork that integrates all the people, content, and tools your team needs to be more engaged and ...

724 views 0 3
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you