Using:
Jira 9.4.4
Adaptavist ScriptRunner for JIRA 7.10.0
I need to send a Slack message using a cron job that isn't possible with Jira Automation.
I've tried copying a couple examples found online, as well as using the script from the Adaptavist Library here: https://library.adaptavist.com/entity/send-notification-to-slack (tried both Data Center version and Server version). I tried a test in both the Scriptrunner console and in jobs to simply send a Slack message "This is a test" and do nothing else, but was unsuccessful. The script seemed to load/buffer for a bit after I clicked "Run" and then nothing happened - no message in the Slack channel, no error message or logs.
I have no coding experience. What am I doing wrong? Do I need to replace the part that says "JIRA_BASEURL"?
This is what I used from the Adaptavist Library (but with a real webhook URL):
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.config.properties.APKeys
import groovyx.net.http.ContentType
import groovyx.net.http.RESTClient
import groovyx.net.http.HttpResponseDecorator
// You have to create a webhook first:
// https://api.slack.com/messaging/webhooks#posting_with_webhooks
// Your webhook is related to one channel or user to which you will be able to send messages
// Once you have your webhook, split it into it's base URL and it's URL path
final webhookBase = 'https://hooks.slack.com'
final webhookPath = '/services/actual/webhookURL/here'
def jiraBaseUrl = ComponentAccessor.applicationProperties.getString(APKeys.JIRA_BASEURL)
// We have to convert this GString into String explicitly here
def message = "This is a test" as String
def body = [
text : message,
]
def response = new RESTClient(webhookBase).post(
path: webhookPath,
contentType: ContentType.HTML,
body: body,
requestContentType: ContentType.JSON
) as HttpResponseDecorator
assert response.status == 200: "Request failed with status $response.status. $response.entity.content.text"