Skip to content

Pipeline 项目

robot 为机器人ID,在 飞书机器人配置 中查看

1. 文本消息

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

2. 群名片消息

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

3. 图片消息

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

4. 富文本消息

shell
pipeline {
    agent any
    stages {
        stage('text'){
            steps {
                echo '发送富文本消息...'
            }
            post {
                success {
                    lark (
                        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": "所有人"
                                ]
                            ]
                        ]
                    )
                }
            }
        }
    }
}

5. 卡片消息

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

6. IMG卡片消息

字段类型说明
titlestring图片标题
altContentstring悬浮(hover)在图片上时展示的说明文案
radiusstring图片圆角半径,支持以下格式:
5px(像素)
20%(百分比)
scale_typestring图片裁剪模式(当图片比例与 size 不一致时生效):
center:居中裁剪
crop_top:顶部裁剪
fit_horizontal:保持完整显示,不裁剪(自动适配)
sizestring图片尺寸(仅在 scale_typecentercrop_top 时生效)
预设值
stretch:超大图(适合高宽比 < 16:9)
large:160×160 px(多图混排)
medium:80×80 px(图文封面)
small:40×40 px(头像)
tiny:16×16 px(图标/备注)
自定义
• 格式:[width]px [height]px,如 "120px 80px"(宽高范围:1–1000px)
transparentboolean是否为透明底色
true:透明背景
false:白色背景(默认)
previewboolean点击后是否放大预览:
true:点击弹出图片查看器,支持放大查看
false:点击触发卡片整体交互,不弹出查看器(默认行为需结合卡片事件)
shell
pipeline {
    agent any
    stages {
        stage('text'){
            steps {
                echo "发送IMG卡片消息..."
            }
            post {
                success {
                    lark (
                        robot: "f72aa1bb-0f0b-47c7-8387-272d266dc25c",
                        type: "CARD",
                        title: "📢 Jenkins 构建通知",
                        text: [
                            "📋 **任务名称**:[${JOB_NAME}](${JOB_URL})",
                            "🔢 **任务编号**:[${BUILD_DISPLAY_NAME}](${BUILD_URL})",
                            "🌟 **构建状态**: <font color='green'>成功</font>",
                            "🕐 **构建用时**: ${currentBuild.duration} ms",
                            "👤 **执  行 者**: ${env.BUILD_USER}",
                            "<at id=all></at>"
                        ],
                        topImg: [
                            mode: "fit_horizontal",
                            imgKey: "img_v2_9b14e850-3757-43ae-96b4-965ed81e7f8g",
                            altContent: "这是正文顶部的图片哦!",
                        ],
                        bottomImg: [
                            mode: "fit_horizontal",
                            imgKey: "img_v2_9b14e850-3757-43ae-96b4-965ed81e7f8g",
                            altContent: "这是正文底部的图片哦!",
                        ],
                        buttons: [
                           [
                              title: "更改记录",
                              url: "${BUILD_URL}changes"
                           ],
                           [
                              title: "控制台",
                              type: "danger",
                              url: "${BUILD_URL}console"
                           ]
                        ]
                    )
                }
            }
        }
    }
}