Skip to content

Instantly share code, notes, and snippets.

@dongfg
Created July 3, 2017 05:38
Show Gist options
  • Save dongfg/a171bcbba33a871b2f1eb2d73d8fd10e to your computer and use it in GitHub Desktop.
Save dongfg/a171bcbba33a871b2f1eb2d73d8fd10e to your computer and use it in GitHub Desktop.
jenkins pipeline send message to DingTalk
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