Skip to content

Commit

Permalink
refactor(Slack): 페이로드를 JSON 객체로 정의하여 쉽게 변경 가능하도록 함
Browse files Browse the repository at this point in the history
  • Loading branch information
limehee committed Jun 19, 2024
1 parent 7689d12 commit 75535d5
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions jenkins/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -148,25 +148,25 @@ pipeline {
}
}

def sendSlackNotification(message, color) {
withEnv([
"SLACK_WEBHOOK_URL=${env.SLACK_WEBHOOK_URL}"
]) {
def payload = """{
"attachments": [
{
"color": "${color}",
"text": "${message.replaceAll('"', '\\"').replaceAll('\n', '\\\\n')}"
}
def sendSlackNotification(String message, String color) {
def payload = [
attachments: [
[
color: color,
text: message.replaceAll('"', '\\"').replaceAll('\n', '\\\\n')
]
}"""
]
]

withEnv(["SLACK_WEBHOOK_URL=${env.SLACK_WEBHOOK_URL}"]) {
def payloadJson = groovy.json.JsonOutput.toJson(payload)
sh """
curl -X POST --data-urlencode 'payload=${payload}' ${SLACK_WEBHOOK_URL}
curl -X POST -H 'Content-type: application/json' --data '${payloadJson}' ${SLACK_WEBHOOK_URL}
"""
}
}


def sendSlackBuildNotification(String message, String color) {
def jobUrl = "${env.JENKINS_DOMAIN}/job/${env.JOB_NAME}"
def consoleOutputUrl = "${jobUrl}/${env.BUILD_NUMBER}/console"
Expand Down

0 comments on commit 75535d5

Please sign in to comment.