XDYB / feishu-notification-plugin

飞书 Jenkins 插件

Home Page:https://721806280.github.io/feishu-notification-plugin-doc

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

🌐 插件简介

feishu-notification-plugin 是一个用于 Jenkins飞书机器人通知插件,可以将 Jenkins 构建过程以及结果通知推送到 飞书 协作平台。 可配置多个的通知时机,包括 构建启动时构建中断构建失败构建成功时构建不稳定等。 支持多种不同类型的消息,包括 文本消息图片消息群名片消息富文本消息卡片消息; 同时该插件还提供了自定义模板变量的功能,使您能够根据自己的需求来定制通知消息的内容和格式。

📝 使用文档

请参考 官方文档

TEXT 消息

pipeline {
    agent any
    stages {
        stage('text'){
            steps {
                echo '发送文本消息...'
            }
            post {
                success {
                    feiShuTalk (
                        robot: 'f72aa1bb-0f0b-47c7-8387-272d266dc25c',
                        type: 'TEXT',
                        text: [
                            "新更新提醒",
                            '<at user_id="all">所有人</at>'
                        ]
                    )
                }
            }
        }
    }
}

群名片消息

pipeline {
    agent any
    stages {
        stage('text'){
            steps {
                echo '发送群名片消息...'
            }
            post {
                success {
                    feiShuTalk (
                        robot: 'f72aa1bb-0f0b-47c7-8387-272d266dc25c',
                        type: 'SHARE_CHAT',
                        shareChatId: 'oc_f5b1a7eb27ae2c7b6adc2a74faf339ff'
                    )
                }
            }
        }
    }
}

图片消息

pipeline {
    agent any
    stages {
        stage('text'){
            steps {
                echo '发送图片消息...'
            }
            post {
                success {
                    feiShuTalk (
                        robot: 'f72aa1bb-0f0b-47c7-8387-272d266dc25c',
                        type: 'IMAGE',
                        imageKey: 'img_ecffc3b9-8f14-400f-a014-05eca1a4310g'
                    )
                }
            }
        }
    }
}

富文本消息

pipeline {
    agent any
    stages {
        stage('text'){
            steps {
                echo '发送富文本消息...'
            }
            post {
                success {
                    feiShuTalk (
                        robot: 'f72aa1bb-0f0b-47c7-8387-272d266dc25c',
                        type: 'POST',
                        title: '项目更新通知',
                        post: [
                            [
                                [
                                    "tag": "text",
                                    "text": "项目有更新: "
                                ],
                                [
                                    "tag": "a",
                                    "text": "请查看",
                                    "href": "https://www.example.com/"  
                                ],
                                [
                                    "tag": "at",
                                    "user_id": "ou_xxxxxx",
                                    "user_name": "tom"
                                ]
                            ],
                            [
                                [
                                    "tag": "text",
                                    "text": "项目有更新:"
                                ],
                                [
                                    "tag": "at",
                                    "user_id": "all",
                                    "user_name": "所有人"
                                ]
                            ]
                        ]
                    )
                }
            }
        }
    }
}

卡片消息

  1. 按钮颜色 type 的取值范围: primary | danger | default
  2. 字体颜色 color 的取值范围: green:绿色文本 | red:红色文本 | grey:灰色文本 | default:白底黑字样式
pipeline {
    agent any
    stages {
        stage('text'){
            steps {
                echo "发送卡片消息..."
            }
            post {
                success {
                    feiShuTalk (
                        robot: "f72aa1bb-0f0b-47c7-8387-272d266dc25c",
                        type: "INTERACTIVE",
                        title: "📢 Jenkins 构建通知",
                        text: [
                            "📋 **任务名称**:[${JOB_NAME}](${JOB_URL})",
                            "🔢 **任务编号**:[${BUILD_DISPLAY_NAME}](${BUILD_URL})",
                            "🌟 **构建状态**: <font color='green'>成功</font>",
                            "🕐 **构建用时**: ${currentBuild.duration} ms",
                            "👤 **执  行 者**: Started by user anonymous",
                            "<at id=all></at>"
                        ],
                        buttons: [
                           [
                              title: "更改记录",
                              url: "${BUILD_URL}changes"
                           ],
                           [
                              title: "控制台",
                              type: "danger",
                              url: "${BUILD_URL}console"
                           ]
                        ]
                    )
                }
            }
        }
    }
}

🧑‍💻 开发服务

IDEA 右侧 maven 控制面板中添加 hpi:run 到启动配置:

远程调试(Remote JVM DEBUG)

1. 命令行模式启动

  1. set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=5005,suspend=n
  2. mvn hpi:run -Djetty.port=8080

2. IDEA启动

  1. 打开 ideamaven 面板,Plugins 下的 hpi 插件
  2. hpi:run 右键选择 Modify Run Configuration.. 设置
  3. 点击 Modify Options 后选择 Add VM Options 选项
  4. VM options 处输入: -Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=5005,suspend=n
  5. 点击运行按钮开始执行 maven 命令(勿使用Debug模式运行)

3. Remote JVM DEBUG

  1. 打开 Run/Debug Configurations 并点击 Add New Configuration 后选择 Remote JVM DEBUG
  2. 配置端口后 Run 运行调试
  3. 启动后控制台打印信息: Listening for transport dt_socket at address: 5005

✅ 开发约定

  1. 使用 Alibaba Java Coding Guidelines 校验代码规范。
  2. 使用 Google Style Guide 统一代码风格。

IDEA下载 intellij-java-google-style.xml 通过 Settings -> Editor Code Style 进行导入。

🔍️ 相关链接

🍻 开源推荐

💚 鸣谢

感谢 JetBrains 提供的免费开源 License

JetBrains

About

飞书 Jenkins 插件

https://721806280.github.io/feishu-notification-plugin-doc

License:MIT License


Languages

Language:Java 93.7%Language:JavaScript 3.7%Language:HTML 2.6%Language:CSS 0.1%