이 문서는 Jira 애드온인 ScriptRunner for Jira에서 Slack으로 커스텀 웹훅을 보내는 스크립트를 공유하기 위해 작성되었다.
사전조건
Slack에서 Incoming webhook 생성 후 채널을 추가한다.
스크립트
다음과 같이 스크립트 작성 후에 Script Console에서 테스트를 해보면 원하는 Slack의 채널에 커스텀 메시지를 보낼 수 있다.
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
final webhookBase = 'https://hooks.slack.com'
final webhookPath = '/services/abc/def/ghi'
def message = "New issue created in project" 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"