In this exercise, we will use a sample code of Adaptavist library in order to create a new “Escalation Service” in Jira (using the plugin Scriptrunner for Jira) to create scheduled alerts from a Jira JQL query to a Slack channel (using a Webhook). (click here to see the sample code)

As first step, go to –> Your Apps –> Create new App

Now go to “Incoming Webhooks” –> Activate incoming Webhook

Now push the button “Add New Webhook to Workspace” and connect to a #channel of your Slack workspace.

Now Allow the Slackbot (App) connect to your channel. The WebHook is installed.

You will see in the Slack channel a message like this:

Copy the WebHook url (we will use it in the source code of the script of the Escalation Service).

Now we are ready to do a test from the Script Console of Scriptrunner for Jira.

Copy this code and replace the KEY of the Issue to be shown in the channel also the WebHook url. Run the code in the Script Console and see the result in the Slack channel.

import com.atlassian.jira.component.ComponentAccessor

def issueManager = ComponentAccessor.getIssueManager()
def issue = issueManager.getIssueByCurrentKey("KAN-7")

// Once you have your webhook, Note the whole url for it in the variable below
final String webhookURL = ""

// Enter a channel name like #channel or a SlackUserId like @UH3DJXYZ7
final String channelOrUserId = "#jira2slackchannel"

def baseUrl = ComponentAccessor.applicationProperties.getString(APKeys.JIRA_BASEURL)
def message = "Issue still open in project ${} : "
def client = new RESTClient("")
def data = [:]

data.put("channel", channelOrUserId)
data.put("text", message)
data.put("iron_emoji", ":ghost:")
            "fallback": "Summary: ${issue.summary}, Reporter: ${issue.reporter}",
            "color"   : "warning",
            "fields"  : [
                    "title": "Summary",
                    "value": issue.summary,
                    "short": true
                    "title": "Reporter",
                    "value": issue.reporter.displayName,
                    "short": true
                    "title": "Status",
                    "value": issue.getStatus().getName(),
                    "short": false
                    "title": "Labels",
                    "value": issue.getLabels().toString(),
                    "short": false
                    "title": "Creation date",
                    "value": issue.getCreated().format("dd/MMM/yy"),
                    "short": false

def response =
    path: new URIBuilder(webhookURL).path,
    contentType: ContentType.HTML,
    body: data,
    requestContentType: ContentType.JSON) as HttpResponseDecorator

assert response.status == 200 : "Request failed with status $response.status. $response.entity.content.text"

Now we are ready to see the result in Slack:

If all is ok, we can create the “Escalation Service” in Jira (using Scriptrunner) to schedule the task.

(Remember to disable two lines in the code)

//def issueManager = ComponentAccessor.getIssueManager()
//def issue = issueManager.getIssueByCurrentKey(“KAN-6”)

That’s all! Enjoy and Happy integration! 😀

By MrAddon

Posted by:.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s