Created
July 3, 2017 05:38
-
-
Save dongfg/a171bcbba33a871b2f1eb2d73d8fd10e to your computer and use it in GitHub Desktop.
jenkins pipeline send message to DingTalk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
node { | |
try { | |
stage('common build stage'){ | |
echo 'build ...' | |
} | |
currentBuild.result = "SUCCESS" | |
} catch(e) { | |
currentBuild.result = "FAIL" | |
} | |
sengMsg(currentBuild.result) | |
} | |
def sengMsg(result){ | |
stage('Send Message') { | |
sendDingTalkMsg(result.equals("SUCCESS")?'Build Successful':'Build Failed') | |
} | |
} | |
def sendDingTalkMsg(buildResult) { | |
def dingTaskUrl = "SET YOUR DingTalk Robot Url Here" | |
def msgData = """ | |
{ | |
"actionCard": { | |
"title": "Build Result", | |
"text": "### ${BUILD_TAG}\n**$buildResult**", | |
"hideAvatar": "0", | |
"btnOrientation": "0", | |
"singleTitle": "View Output", | |
"singleURL": "${BUILD_URL}/consoleText" | |
}, | |
"msgtype": "actionCard", | |
"hideAvatar": "1" | |
} | |
""" | |
def response = httpRequest acceptType: 'APPLICATION_JSON', contentType: 'APPLICATION_JSON', httpMode: 'POST', requestBody: msgData, url: dingTaskUrl | |
println('Response: '+response.content) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment