Please use the script below as a shell command and save to /usr/local/bin/lark
in the execution environment
#!/usr/bin/env bash
action=$1
url=$2
# This method won't work
#"duration": $(echo $(($(date +%s%N)/1000000 - ${TAG_TIMESTAMP:-0}))),
JSON_BODY=$(cat <<EOF
{
"action": "${action}",
"type": "job",
"name": "${BUILD_TAG}",
"order": "${GIT_BRANCH}-${GIT_COMMIT}",
"buildurl": "${BUILD_URL}",
"joburl": "${JOB_URL}",
"duration": 0,
"causeby": "点击【查看】按钮"
}
EOF
)
curl -si \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-X POST --data "$JSON_BODY" \
${url}
pipeline {
agent any
stages {
stage('Hello World') {
....
}
}
post {
aborted {
sh 'lark "abort" "<webhook url>"'
}
failure {
sh 'lark "failed" "<webhook url>"'
}
success {
sh 'lark "success" "<webhook url>"'
}
}
}
the url of
webhook
will look like this:https://open.feishu.cn/officialapp/notify/xxxxx
More variable exposures may be possible via: https://opensource.triology.de/jenkins/pipeline-syntax/globals#currentBuild