CNB配置企业微信机器人
实战-CNB配置企业微信机器人推送构建结果-20250723(测试成功)

目录
[[toc]]
[toc]
背景


参考文档

其它机器人

邮箱通知

CNB官方文档

通过 email 发送构建消息的插件。
在 云原生构建 上使用
1main:
2 push:
3 - stages:
4 - name: notify
5 image: drillster/drone-email
6 settings:
7 host: smtp.some-server.com
8 username: foo
9 password: bar
10 from: drone@your-domain.com
参数
from : 从此地址发送通知。
host : SMTP服务器主机。
port : SMTP服务器主机 587。
username : SMTP 用户名。
password : SMTP 密码。
skip_verify : 跳过证书验证,默认为 false。
recipients : 发送此邮件的收件人列表。
recipients_file : 用于加载其他收件人的文件名。
recipients_only : 不将邮件发送给提交作者,而只发送给收件人,默认为 false。
subject : subject 行模版。
body : 电子邮件正文模板。
attachment : 附加到已发送邮件的可选文件。
1main:
2 push:
3 - stages:
4 - name: notify
5 image: drillster/drone-email
6 settings:
7 host: smtp.qq.com
8 port: 465
9 username: 2675263825@qq.com # 完整QQ邮箱地址
10 password: "wuietiubwgrfecgd" # 需使用授权码而非QQ密码
11 from: 2675263825@qq.com # 发件人邮箱
12 recipients: # 收件人列表
13 - 2675263825@qq.com
14 ssl: true # 必须启用SSL
更多用法
更多用法参考:drillster/drone-email。
gpt
gpt提问:
1main:
2 push:
3 - stages:
4 - name: notify
5 image: drillster/drone-email
6 settings:
7 host: smtp.some-server.com
8 username: foo
9 password: bar
10 from: drone@your-domain.com
11
12这里如果换成自己的qq邮箱,2675263825@qq.com,需要改些什么内容呢?
回答
修改后的配置示例
1main:
2 push:
3 - stages:
4 - name: notify
5 image: drillster/drone-email
6 settings:
7 host: smtp.qq.com # QQ邮箱SMTP服务器
8 port: 465 # SSL加密端口
9 username: 26xxxx@qq.com # 完整QQ邮箱地址
10 password: "xxxxxxxxxx" # 需使用授权码而非QQ密码
11 from: 2xxxxxx@qq.com # 发件人邮箱
12 recipients: # 收件人列表
13 - target@example.com
14 ssl: true # 必须启用SSL
1main:
2 push:
3 - stages:
4 - name: notify
5 image: drillster/drone-email
6 settings:
7 host: smtp.qq.com # QQ邮箱SMTP服务器
8 port: 465 # SSL加密端口
9 username: 2xxxxxx@qq.com # 完整QQ邮箱地址
10 password: "wuixxecgd" # 需使用授权码而非QQ密码
11 from: 26xxxxx5@qq.com # 发件人邮箱
12 recipients: # 收件人列表
13 - target@example.com
14 ssl: true # 必须启用SSL
关键修改点说明
| 参数 | 原值 | 修改为 | 注意事项 |
|---|---|---|---|
host | smtp.some-server.com | smtp.qq.com | QQ邮箱SMTP服务器地址 |
port | 默认25 | 465 或 587 | 必须使用加密端口 |
username | foo | 2675263825@qq.com | 完整邮箱地址 |
password | bar | 授权码 | 非QQ密码,需单独生成 |
ssl | 未指定 | true | 必须启用SSL加密 |
前置准备(必须完成)
获取QQ邮箱授权码
- 登录QQ邮箱 → 设置 → 「账户」 → 「POP3/IMAP/SMTP服务」
- 生成授权码(16位随机字符串),流程如下:
1开启服务 → 验证密保 → 生成授权码 → 复制保存
检查安全设置
- 确保账户未启用「安全登录」(否则会拦截SMTP连接)
高级配置建议
1settings:
2 # 基础配置
3 host: smtp.qq.com
4 port: 465
5 username: 2xxxxxxxxx25@qq.com
6 password: "vzthqabcdefghijk" # 示例授权码
7
8 # 邮件内容定制
9 from: Drone CI xxxqq.com> # 带名称的发件人
10 recipients:
11 - admin@company.com
12 subject: "构建通知: {{ repo.name }} #{{ build.number }}"
13 body: |
14 项目: {{ repo.name }}
15 状态: {{ build.status }}
16 详情: {{ build.link }}
17
18 # 连接控制
19 ssl: true
20 skip_verify: false # 生产环境建议保持false验证证书
常见问题排查
连接被拒绝
- 检查防火墙是否放行465端口
- 尝试切换端口
465→587
认证失败
- 确认使用授权码而非QQ密码
- 检查邮箱地址是否完整(必须带
@qq.com)
邮件被拦截
- 在QQ邮箱设置中关闭「安全登录」
- 添加发件IP到QQ邮箱白名单
其他邮箱服务商参考
| 服务商 | SMTP服务器 | 端口 | 加密 |
|---|---|---|---|
| 163邮箱 | smtp.163.com | 465/994 | SSL |
| Gmail | smtp.gmail.com | 587 | TLS |
| Outlook | smtp.office365.com | 587 | STARTTLS |
注: 国内邮箱建议优先使用QQ/163,Gmail需特殊配置且可能被墙
方案1
ok-但不够优雅
代码:
1master:
2 push:
3 - runner:
4 cpus: 16
5 services:
6 - docker
7 - git-clone-yyds
8 imports:
9 - https://cnb.cool/onedayxyy/secret/-/blob/main/envs.yml
10 docker:
11 image: docker.cnb.cool/znb/images/node:18
12 volumes:
13 - /data/.cache:copy-on-write #声明式的构建缓存
14 stages:
15 - name: 🖨️ 打印环境
16 if: |
17 [ "$CNB_COMMIT_MESSAGE_TITLE" = "BUILD" ]
18 script: |
19 node -v && npm -v && yarn -v && pnpm -v
20 - name: 📦️ 安装依赖
21 if: |
22 [ "$CNB_COMMIT_MESSAGE_TITLE" = "BUILD" ]
23 script: |
24 pnpm install
25
26 - name: ⚗️ 编译项目
27 if: |
28 [ "$CNB_COMMIT_MESSAGE_TITLE" = "BUILD" ]
29 script: |
30 pnpm docs:build # VitePress 专用命令
31 - name: 🚚 发布制品
32 if: |
33 [ "$CNB_COMMIT_MESSAGE_TITLE" = "BUILD" ]
34 image: tencentcom/rsync
35 settings:
36 user: ${SSH_USER}
37 key: ${SSH_KEY}
38 port: 22
39 hosts:
40 - ${ECS_IP}
41 source: docs/.vitepress/dist/
42 target: /root/rsync/rsync-vitepress/dist/
43 delete: true
44 prescript:
45 - echo "prescript"
46 - ls -l /root/rsync/rsync-vitepress/dist/
47 # script:
48 # - echo "after script"
49 # - ls -l /root/rsync/rsync-vitepress/dist/
50 # - date
51 # # - bash /root/website_music.sh
52 # - aliyun cdn RefreshObjectCaches --ObjectType File --ObjectPath "onedayxyy.cn/" #刷新阿里云cdn缓存
53
54 # - name: 🔔 发布通知
55 # image: tencentcom/wecom-message
56 # settings:
57 # robot: ${WECOM_BOT}
58 # msgType: markdown
59 # content: |
60 # > **🎉 JenkinsGuide 又一次发布啦!**
61 # > **构建时间:** $CUSTOM_ENV_DATE_INFO
62 # > **提交信息:** $CNB_COMMIT_MESSAGE_TITLE
63 # > **仓库地址:** [$CNB_REPO_URL_HTTPS]($CNB_REPO_URL_HTTPS)
64
65 - name: 🧘♂️ 刷新缓存
66 image: docker.cnb.cool/znb/cdn-refresh
67 settings:
68 ak: "${TENCENT_OPSRE_AK}"
69 sk: "${TENCENT_OPSRE_SK}"
70 kind: "tencenteo"
71 rtype: "path"
72 domain: "onedayxyy.cn"
73 urls:
74 - "https://onedayxyy.cn/"
75
76 #同步仓库到gitee
77 - name: sync to gitee
78 image: tencentcom/git-sync
79 settings:
80 branch: master
81 auth_type: https
82 username: ${GIT_USERNAME}
83 password: ${GIT_ACCESS_TOKEN}
84 target_url: https://gitee.com/onlyonexl/vitepress-theme-teek-one-private.git
85 # git_email: 'github-actions[bot]@users.noreply.github.com'
86
87 - name: notify
88 image: drillster/drone-email
89 settings:
90 host: smtp.qq.com # QQ邮箱SMTP服务器
91 port: 465 # SSL加密端口
92 username: 2675263825@qq.com # 完整QQ邮箱地址
93 password: "wuietiubwgrfecgd" # 需使用授权码而非QQ密码
94 from: 2675263825@qq.com # 发件人邮箱
95 recipients: # 收件人列表
96 - 2675263825@qq.com
97 ssl: true
效果:

方案2
ok-但不够优雅
代码:
1master:
2 push:
3 - runner:
4 cpus: 16
5 services:
6 - docker
7 - git-clone-yyds
8 imports:
9 - https://cnb.cool/onedayxyy/secret/-/blob/main/envs.yml
10 docker:
11 image: docker.cnb.cool/znb/images/node:18
12 volumes:
13 - /data/.cache:copy-on-write #声明式的构建缓存
14 stages:
15 - name: 🖨️ 打印环境
16 if: |
17 [ "$CNB_COMMIT_MESSAGE_TITLE" = "BUILD" ]
18 script: |
19 node -v && npm -v && yarn -v && pnpm -v
20 - name: 📦️ 安装依赖
21 if: |
22 [ "$CNB_COMMIT_MESSAGE_TITLE" = "BUILD" ]
23 script: |
24 pnpm install
25
26 - name: ⚗️ 编译项目
27 if: |
28 [ "$CNB_COMMIT_MESSAGE_TITLE" = "BUILD" ]
29 script: |
30 pnpm docs:build # VitePress 专用命令
31 - name: 🚚 发布制品
32 if: |
33 [ "$CNB_COMMIT_MESSAGE_TITLE" = "BUILD" ]
34 image: tencentcom/rsync
35 settings:
36 user: ${SSH_USER}
37 key: ${SSH_KEY}
38 port: 22
39 hosts:
40 - ${ECS_IP}
41 source: docs/.vitepress/dist/
42 target: /root/rsync/rsync-vitepress/dist/
43 delete: true
44 prescript:
45 - echo "prescript"
46 - ls -l /root/rsync/rsync-vitepress/dist/
47 # script:
48 # - echo "after script"
49 # - ls -l /root/rsync/rsync-vitepress/dist/
50 # - date
51 # # - bash /root/website_music.sh
52 # - aliyun cdn RefreshObjectCaches --ObjectType File --ObjectPath "onedayxyy.cn/" #刷新阿里云cdn缓存
53
54 # - name: 🔔 发布通知
55 # image: tencentcom/wecom-message
56 # settings:
57 # robot: ${WECOM_BOT}
58 # msgType: markdown
59 # content: |
60 # > **🎉 JenkinsGuide 又一次发布啦!**
61 # > **构建时间:** $CUSTOM_ENV_DATE_INFO
62 # > **提交信息:** $CNB_COMMIT_MESSAGE_TITLE
63 # > **仓库地址:** [$CNB_REPO_URL_HTTPS]($CNB_REPO_URL_HTTPS)
64
65 - name: 🧘♂️ 刷新缓存
66 image: docker.cnb.cool/znb/cdn-refresh
67 settings:
68 ak: "${TENCENT_OPSRE_AK}"
69 sk: "${TENCENT_OPSRE_SK}"
70 kind: "tencenteo"
71 rtype: "path"
72 domain: "onedayxyy.cn"
73 urls:
74 - "https://onedayxyy.cn/"
75
76 #同步仓库到gitee
77 - name: sync to gitee
78 image: tencentcom/git-sync
79 settings:
80 branch: master
81 auth_type: https
82 username: ${GIT_USERNAME}
83 password: ${GIT_ACCESS_TOKEN}
84 target_url: https://gitee.com/onlyonexl/vitepress-theme-teek-one-private.git
85 # git_email: 'github-actions[bot]@users.noreply.github.com'
86
87 - name: notify
88 image: drillster/drone-email
89 settings:
90 host: smtp.qq.com # QQ邮箱SMTP服务器
91 port: 465 # SSL加密端口
92 username: 2675263825@qq.com # 完整QQ邮箱地址
93 password: "wuietiubwgrfecgd" # 需使用授权码而非QQ密码
94 from: 2675263825@qq.com # 发件人邮箱
95 recipients: # 收件人列表
96 - 2675263825@qq.com
97 ssl: true
98 subject: "构建通知: {{ repo.name }} #{{ build.number }}"
99 body: |
100 项目: {{ repo.name }}
101 状态: {{ build.status }}
102 详情: {{ build.link }}
效果:

方案3-企业微信机器人❤️(推荐)
参考:
可以先拉一个微信好友,创建群聊,在剔除好友,就可以可哦。😊
- 创建群机器人

获取自己的群机器人id:
1https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
- 最终代码:
.cnb.yml
1master:
2 push:
3 - runner:
4 cpus: 16
5 services:
6 - docker
7 - git-clone-yyds
8 imports:
9 - https://cnb.cool/onedayxyy/secret/-/blob/main/envs.yml
10 docker:
11 image: docker.cnb.cool/znb/images/node:18
12 volumes:
13 - /data/.cache:copy-on-write #声明式的构建缓存
14 stages:
15 - name: set env
16 script: echo -n $(date "+%Y-%m-%d %H:%M")
17 exports:
18 info: CUSTOM_ENV_DATE_INFO
19 - name: 🖨️ 打印环境
20 if: |
21 [ "$CNB_COMMIT_MESSAGE_TITLE" = "BUILD" ]
22 script: |
23 node -v && npm -v && yarn -v && pnpm -v
24 - name: 📦️ 安装依赖
25 if: |
26 [ "$CNB_COMMIT_MESSAGE_TITLE" = "BUILD" ]
27 script: |
28 pnpm install
29
30 - name: ⚗️ 编译项目
31 if: |
32 [ "$CNB_COMMIT_MESSAGE_TITLE" = "BUILD" ]
33 script: |
34 pnpm docs:build # VitePress 专用命令
35 - name: 🚚 发布制品
36 if: |
37 [ "$CNB_COMMIT_MESSAGE_TITLE" = "BUILD" ]
38 image: tencentcom/rsync
39 settings:
40 user: ${SSH_USER}
41 key: ${SSH_KEY}
42 port: 22
43 hosts:
44 - ${ECS_IP}
45 source: docs/.vitepress/dist/
46 target: /root/rsync/rsync-vitepress/dist/
47 delete: true
48 prescript:
49 - echo "prescript"
50 - ls -l /root/rsync/rsync-vitepress/dist/
51 # script:
52 # - echo "after script"
53 # - ls -l /root/rsync/rsync-vitepress/dist/
54 # - date
55 # # - bash /root/website_music.sh
56 # - aliyun cdn RefreshObjectCaches --ObjectType File --ObjectPath "onedayxyy.cn/" #刷新阿里云cdn缓存
57
58
59
60 - name: 🧘♂️ 刷新缓存
61 image: docker.cnb.cool/znb/cdn-refresh
62 settings:
63 ak: "${TENCENT_OPSRE_AK}"
64 sk: "${TENCENT_OPSRE_SK}"
65 kind: "tencenteo"
66 rtype: "path"
67 domain: "onedayxyy.cn"
68 urls:
69 - "https://onedayxyy.cn/"
70
71 #同步仓库到gitee
72 - name: sync to gitee
73 image: tencentcom/git-sync
74 settings:
75 branch: master
76 auth_type: https
77 username: ${GIT_USERNAME}
78 password: ${GIT_ACCESS_TOKEN}
79 target_url: https://gitee.com/onlyonexl/vitepress-theme-teek-one-private.git
80 # git_email: 'github-actions[bot]@users.noreply.github.com'
81
82 - name: 🔔 发布通知
83 image: tencentcom/wecom-message
84 settings:
85 robot: ${WECOM_BOT}
86 msgType: markdown
87 content: |
88 > **🎉 One Blog 又一次发布成功啦!**
89 > **构建时间:** $CUSTOM_ENV_DATE_INFO
90 > **构建id:** $CNB_BUILD_ID
91 > **提交id:** $CNB_COMMIT_SHORT
92 > **构建分支:** $CNB_BRANCH
93 > **提交信息:** $CNB_COMMIT_MESSAGE_TITLE
94 > **提交者:** $CNB_COMMITTER
95 > **仓库地址:** [$CNB_REPO_URL_HTTPS]($CNB_REPO_URL_HTTPS)
- 效果

结束。
关于我
我的博客主旨:
- 排版美观,语言精炼;
- 文档即手册,步骤明细,拒绝埋坑,提供源码;
- 本人实战文档都是亲测成功的,各位小伙伴在实际操作过程中如有什么疑问,可随时联系本人帮您解决问题,让我们一起进步!
🍀 个人网站

🍀 微信二维码
x2675263825 (舍得), qq:2675263825。

🍀 微信公众号
《云原生架构师实战》

🍀 csdn
https://blog.csdn.net/weixin_39246554?spm=1010.2135.3001.5421

🍀 知乎
https://www.zhihu.com/people/foryouone

最后
如果你还有疑惑,可以去我的网站查看更多内容或者联系我帮忙查看。
如果你有更好的方式,评论区留言告诉我。谢谢!
好了,本次就到这里了,感谢大家阅读,最后祝大家生活快乐,每天都过的有意义哦,我们下期见!

