|
|
@@ -1,41 +0,0 @@
|
|
|
-#!/usr/bin/env groovy
|
|
|
-
|
|
|
-def call(Map args=[:]) {
|
|
|
- String webhook = args.webhook ?: credentialsId('feishu-webhook')
|
|
|
- String secret = args.secret ?: ''
|
|
|
-
|
|
|
- def result = currentBuild.currentResult // SUCCESS / FAILURE / ABORTED
|
|
|
- def emoji = result == 'SUCCESS' ? '✅' : '❌'
|
|
|
- def ts = (System.currentTimeMillis()/1000) as int
|
|
|
- def sign = ''
|
|
|
- if (secret) {
|
|
|
- def mac = javax.crypto.Mac.getInstance("HmacSHA256")
|
|
|
- mac.init(new javax.crypto.spec.SecretKeySpec("${ts}\n${secret}".bytes,"HmacSHA256"))
|
|
|
- sign = mac.doFinal().encodeBase64().toString()
|
|
|
- }
|
|
|
-
|
|
|
- def body = [
|
|
|
- msg_type: "interactive",
|
|
|
- card: [
|
|
|
- header: [title: [tag: "plain_text", content: "${emoji} Jenkins 构建${result}"]],
|
|
|
- elements: [
|
|
|
- [tag: "div", text: [tag: "lark_md", content:
|
|
|
- "**项目**:${env.JOB_NAME} #${env.BUILD_NUMBER}\n**结果**:${result}\n**耗时**:${currentBuild.durationString.replace(' and counting','')}"]],
|
|
|
- [tag: "action", actions: [
|
|
|
- [tag: "button", type: "primary", text: [tag: "plain_text", content: "查看构建"], url: env.BUILD_URL]
|
|
|
- ]]
|
|
|
- ]
|
|
|
- ]
|
|
|
- ]
|
|
|
- if (secret) {
|
|
|
- body += [timestamp: ts as String, sign: sign]
|
|
|
- }
|
|
|
-
|
|
|
- withCredentials([string(credentialsId: webhook, variable: 'URL')]) {
|
|
|
- httpRequest url: env.URL,
|
|
|
- httpMode: 'POST',
|
|
|
- contentType: 'APPLICATION_JSON',
|
|
|
- requestBody: groovy.json.JsonOutput.toJson(body),
|
|
|
- consoleLogResponseBody: true
|
|
|
- }
|
|
|
-}
|