Add vars/notifyLark.groovy
This commit is contained in:
58
vars/notifyLark.groovy
Normal file
58
vars/notifyLark.groovy
Normal file
@@ -0,0 +1,58 @@
|
||||
def call(Map args = [:]) {
|
||||
|
||||
// ===== 参数 =====
|
||||
def publishEnvs = args.publishEnvs ?: 'production'
|
||||
def branchName = args.branchName ?: (env.BRANCH_NAME ?: 'unknown')
|
||||
|
||||
// ===== Jenkins 内建上下文 =====
|
||||
def buildStatus = currentBuild.currentResult ?: 'UNKNOWN'
|
||||
def buildNumber = env.BUILD_NUMBER
|
||||
def buildUrl = env.BUILD_URL
|
||||
def jobName = env.JOB_NAME
|
||||
def triggerBy = env.BUILD_USER ?: 'unknown'
|
||||
|
||||
// ===== 状态标签 =====
|
||||
def statusTag = [
|
||||
SUCCESS : "<text_tag color='turquoise'>通过</text_tag>",
|
||||
FAILURE : "<text_tag color='red'>失败</text_tag>",
|
||||
UNSTABLE: "<text_tag color='orange'>不稳定</text_tag>",
|
||||
ABORTED : "<text_tag color='neutral'>已中止</text_tag>"
|
||||
][buildStatus] ?: "<text_tag color='neutral'>未知状态</text_tag>"
|
||||
|
||||
def commitDiff = "[查看变更记录](${buildUrl}changes)"
|
||||
|
||||
// ===== 凭证 =====
|
||||
withCredentials([
|
||||
string(credentialsId: 'FEISHU_WEBHOOK', variable: 'FEISHU_WEBHOOK')
|
||||
]) {
|
||||
|
||||
def payload = [
|
||||
msg_type: 'interactive',
|
||||
card: [
|
||||
type: 'template',
|
||||
data: [
|
||||
template_id: 'AAq2iv39m3lv5',
|
||||
template_version_name: '1.0.5',
|
||||
template_variable: [
|
||||
build_title : jobName,
|
||||
status_tag : statusTag,
|
||||
build_number: buildNumber,
|
||||
publish_envs: publishEnvs,
|
||||
commit_diff : commitDiff,
|
||||
build_branch: branchName,
|
||||
trigger_by : triggerBy,
|
||||
build_url : [ url: buildUrl ]
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
|
||||
httpRequest(
|
||||
httpMode: 'POST',
|
||||
contentType: 'APPLICATION_JSON',
|
||||
url: env.FEISHU_WEBHOOK,
|
||||
requestBody: groovy.json.JsonOutput.toJson(payload),
|
||||
validResponseCodes: '200:299'
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user