Skip to content

edisonwsk/feishu-notify-plugin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Feishu Notify Jenkins Plugin / 飞书通知Jenkins插件

English | 中文


English

This is a Feishu (Lark) notification plugin for Jenkins that supports sending notification messages to Feishu group chats after build completion.

Features

  • ✅ Support for traditional Jenkins Jobs and Pipeline mode
  • ✅ Support for global configuration with project inheritance or override
  • ✅ Support for Feishu bot webhook notifications
  • ✅ Support for signature verification security mechanism
  • ✅ Customizable notification timing (success/failure/unstable/aborted)
  • ✅ Support for custom message content and colors
  • ✅ Built-in connection testing functionality
  • ✅ Multi-language support (English/Chinese)

Installation

Method 1: Build from Source

git clone <repository-url>
cd feishu-notify-plugin
mvn clean package

Then upload the generated target/feishu-notify.hpi file in Jenkins management page.

Method 2: Jenkins Plugin Manager

  1. Go to Jenkins -> Manage Jenkins -> Manage Plugins
  2. Search for "Feishu Notify" in "Available" plugins
  3. Install and restart Jenkins

Configuration

Global Configuration

  1. Go to Jenkins -> Manage Jenkins -> Configure System
  2. Find "Feishu Notification Global Configuration" section
  3. Configure global Webhook URL and secret (optional)
  4. Check "Enable Global Configuration"

Getting Feishu Webhook URL

  1. In Feishu group chat, click settings button in upper right corner
  2. Select "Bot" -> "Add Bot" -> "Custom Bot"
  3. Set bot name and description
  4. Copy the generated Webhook address (format: https://open.feishu.cn/open-apis/bot/v2/hook/...)
  5. Set signature secret if security verification is needed

Usage

Traditional Job Configuration

  1. In Job configuration page, find "Post-build Actions" section
  2. Add "Feishu Notification" action
  3. Configure Webhook URL (optional, uses global configuration if not set)
  4. Select notification timing
  5. Add custom message (optional)

Pipeline Usage

Use feishuNotify step in Jenkinsfile:

pipeline {
    agent any
    stages {
        stage('Build') {
            steps {
                echo 'Building...'
                // Your build steps
            }
        }
    }
    post {
        success {
            feishuNotify(
                message: 'Build completed successfully!',
                title: 'Jenkins Build Notification',
                color: 'green'
            )
        }
        failure {
            feishuNotify(
                message: 'Build failed, please check logs',
                title: 'Jenkins Build Notification',
                color: 'red'
            )
        }
    }
}

Pipeline Parameters

Parameter Type Required Description
webhookUrl String No Feishu Webhook URL, uses global configuration if not set
secret String No Signature secret, uses global configuration if not set
message String Yes Message content
title String No Message title, defaults to "Jenkins Pipeline Notification"
color String No Message color: blue, green, yellow, red
atAll Boolean No Whether to @all members, defaults to false

Configuration Priority

  1. Direct configuration in Pipeline step (highest priority)
  2. Job-level configuration
  3. Global configuration (lowest priority)

If a configuration item is not set at a higher priority level, the next level configuration will be used automatically.


中文

这是一个用于Jenkins的飞书(Lark)通知插件,支持在构建完成后向飞书群聊发送通知消息。

功能特性

  • ✅ 支持传统Jenkins Job和Pipeline模式
  • ✅ 支持全局配置,项目可继承或覆盖
  • ✅ 支持飞书机器人Webhook通知
  • ✅ 支持签名验证安全机制
  • ✅ 可自定义通知时机(成功/失败/不稳定/中止)
  • ✅ 支持自定义消息内容和颜色
  • ✅ 提供连接测试功能
  • ✅ 多语言支持(中文/英文)

安装方法

方法1: 从源码构建

git clone <repository-url>
cd feishu-notify-plugin
mvn clean package

然后在Jenkins管理页面上传生成的target/feishu-notify.hpi文件。

方法2: Jenkins插件管理器

  1. 进入Jenkins -> 系统管理 -> 插件管理
  2. 在"可选插件"中搜索"Feishu Notify"
  3. 安装并重启Jenkins

配置说明

全局配置

  1. 进入Jenkins -> 系统管理 -> 系统配置
  2. 找到"飞书通知全局配置"部分
  3. 配置全局Webhook URL和签名密钥(可选)
  4. 勾选"启用全局配置"

获取飞书Webhook URL

  1. 在飞书群聊中,点击右上角设置按钮
  2. 选择"机器人" -> "添加机器人" -> "自定义机器人"
  3. 设置机器人名称和描述
  4. 复制生成的Webhook地址(格式: https://open.feishu.cn/open-apis/bot/v2/hook/...)
  5. 如需安全验证,可设置签名密钥

使用方法

传统Job配置

  1. 在Job配置页面,找到"构建后操作"部分
  2. 添加"飞书通知"操作
  3. 配置Webhook URL(可选,未配置时使用全局配置)
  4. 选择通知时机
  5. 添加自定义消息(可选)

Pipeline使用

在Jenkinsfile中使用feishuNotify步骤:

pipeline {
    agent any
    stages {
        stage('Build') {
            steps {
                echo 'Building...'
                // 你的构建步骤
            }
        }
    }
    post {
        success {
            feishuNotify(
                message: '构建成功完成!',
                title: 'Jenkins构建通知',
                color: 'green'
            )
        }
        failure {
            feishuNotify(
                message: '构建失败,请检查日志',
                title: 'Jenkins构建通知',
                color: 'red'
            )
        }
    }
}

Pipeline参数说明

参数 类型 必填 说明
webhookUrl String 飞书Webhook URL,未设置时使用全局配置
secret String 签名密钥,未设置时使用全局配置
message String 消息内容
title String 消息标题,默认为"Jenkins Pipeline通知"
color String 消息颜色:blue(蓝色)、green(绿色)、yellow(黄色)、red(红色)
atAll Boolean 是否@所有人,默认false

配置优先级

  1. Pipeline步骤中的直接配置 (最高优先级)
  2. Job级别的配置
  3. 全局配置 (最低优先级)

如果某个配置项在高优先级中未设置,会自动使用下一级的配置。

开发说明

环境要求

  • Java 8+
  • Maven 3.6+
  • Jenkins 2.361.4+

构建命令

# 编译
mvn compile

# 运行测试
mvn test

# 打包
mvn package

# 启动测试Jenkins实例
mvn hpi:run

许可证

MIT License

贡献

欢迎提交Issue和Pull Request!

更新日志

v1.0.0

  • 初始版本发布
  • 支持基本的飞书通知功能
  • 支持全局配置
  • 支持Pipeline模式
  • 多语言支持(中文/英文)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published