1、gradle finish方法中获取编译成功和失败的消息
gradle.buildFinished {
BuildResult buildResult ->
project?.gradle?.startParameter?.taskRequests?.forEach {
it?.args?.forEach {
if (it?.contains("assemble")) {
if (buildResult.failure) {
notification("Build FAILED")
} else {
notification("Build SUCCESSFUL")
}
}
}
}
}
def notification(String message) {
exec {
commandLine 'sh', "${project.projectDir}/notification.sh", message
}
}
2、发送通知notification.sh
#!/bin/sh
# 获取当前分支名
BRANCH=$(git rev-parse --abbrev-ref HEAD)
PARAM="*** $BRANCH $1"
# 获取当前用户名
USERNAME=$USER
# 向******发送通知
curl --location --request POST 'http://*****************************' \
--header 'Content-Type:application/json' \
--data-raw "{\"users\": \"$USERNAME\",\"text\": \"$PARAM\"}"