CNB配置企业微信机器人
实战-CNB配置企业微信机器人推送构建结果-20250723(测试成功)
目录
[toc]
背景
参考文档
其它机器人
邮箱通知
CNB官方文档
通过 email 发送构建消息的插件。
在 云原生构建 上使用
main:
push:
- stages:
- name: notify
image: drillster/drone-email
settings:
host: smtp.some-server.com
username: foo
password: bar
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 : 附加到已发送邮件的可选文件。
main:
push:
- stages:
- name: notify
image: drillster/drone-email
settings:
host: smtp.qq.com
port: 465
username: 2675263825@qq.com # 完整QQ邮箱地址
password: "wuietiubwgrfecgd" # 需使用授权码而非QQ密码
from: 2675263825@qq.com # 发件人邮箱
recipients: # 收件人列表
- 2675263825@qq.com
ssl: true # 必须启用SSL
更多用法
更多用法参考:drillster/drone-email。
gpt
gpt提问:
main:
push:
- stages:
- name: notify
image: drillster/drone-email
settings:
host: smtp.some-server.com
username: foo
password: bar
from: drone@your-domain.com
这里如果换成自己的qq邮箱,2675263825@qq.com,需要改些什么内容呢?
回答
修改后的配置示例
main:
push:
- stages:
- name: notify
image: drillster/drone-email
settings:
host: smtp.qq.com # QQ邮箱SMTP服务器
port: 465 # SSL加密端口
username: 26xxxx@qq.com # 完整QQ邮箱地址
password: "xxxxxxxxxx" # 需使用授权码而非QQ密码
from: 2xxxxxx@qq.com # 发件人邮箱
recipients: # 收件人列表
- target@example.com
ssl: true # 必须启用SSL
main:
push:
- stages:
- name: notify
image: drillster/drone-email
settings:
host: smtp.qq.com # QQ邮箱SMTP服务器
port: 465 # SSL加密端口
username: 2xxxxxx@qq.com # 完整QQ邮箱地址
password: "wuixxecgd" # 需使用授权码而非QQ密码
from: 26xxxxx5@qq.com # 发件人邮箱
recipients: # 收件人列表
- target@example.com
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位随机字符串),流程如下:
开启服务 → 验证密保 → 生成授权码 → 复制保存
检查安全设置
- 确保账户未启用「安全登录」(否则会拦截SMTP连接)
高级配置建议
settings:
# 基础配置
host: smtp.qq.com
port: 465
username: 2xxxxxxxxx25@qq.com
password: "vzthqabcdefghijk" # 示例授权码
# 邮件内容定制
from: Drone CI xxxqq.com> # 带名称的发件人
recipients:
- admin@company.com
subject: "构建通知: {{ repo.name }} #{{ build.number }}"
body: |
项目: {{ repo.name }}
状态: {{ build.status }}
详情: {{ build.link }}
# 连接控制
ssl: true
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-但不够优雅
代码:
master:
push:
- runner:
cpus: 16
services:
- docker
- git-clone-yyds
imports:
- https://cnb.cool/onedayxyy/secret/-/blob/main/envs.yml
docker:
image: docker.cnb.cool/znb/images/node:18
volumes:
- /data/.cache:copy-on-write #声明式的构建缓存
stages:
- name: 🖨️ 打印环境
if: |
[ "$CNB_COMMIT_MESSAGE_TITLE" = "BUILD" ]
script: |
node -v && npm -v && yarn -v && pnpm -v
- name: 📦️ 安装依赖
if: |
[ "$CNB_COMMIT_MESSAGE_TITLE" = "BUILD" ]
script: |
pnpm install
- name: ⚗️ 编译项目
if: |
[ "$CNB_COMMIT_MESSAGE_TITLE" = "BUILD" ]
script: |
pnpm docs:build # VitePress 专用命令
- name: 🚚 发布制品
if: |
[ "$CNB_COMMIT_MESSAGE_TITLE" = "BUILD" ]
image: tencentcom/rsync
settings:
user: ${SSH_USER}
key: ${SSH_KEY}
port: 22
hosts:
- ${ECS_IP}
source: docs/.vitepress/dist/
target: /root/rsync/rsync-vitepress/dist/
delete: true
prescript:
- echo "prescript"
- ls -l /root/rsync/rsync-vitepress/dist/
# script:
# - echo "after script"
# - ls -l /root/rsync/rsync-vitepress/dist/
# - date
# # - bash /root/website_music.sh
# - aliyun cdn RefreshObjectCaches --ObjectType File --ObjectPath "onedayxyy.cn/" #刷新阿里云cdn缓存
# - name: 🔔 发布通知
# image: tencentcom/wecom-message
# settings:
# robot: ${WECOM_BOT}
# msgType: markdown
# content: |
# > **🎉 JenkinsGuide 又一次发布啦!**
# > **构建时间:** $CUSTOM_ENV_DATE_INFO
# > **提交信息:** $CNB_COMMIT_MESSAGE_TITLE
# > **仓库地址:** [$CNB_REPO_URL_HTTPS]($CNB_REPO_URL_HTTPS)
- name: 🧘♂️ 刷新缓存
image: docker.cnb.cool/znb/cdn-refresh
settings:
ak: "${TENCENT_OPSRE_AK}"
sk: "${TENCENT_OPSRE_SK}"
kind: "tencenteo"
rtype: "path"
domain: "onedayxyy.cn"
urls:
- "https://onedayxyy.cn/"
#同步仓库到gitee
- name: sync to gitee
image: tencentcom/git-sync
settings:
branch: master
auth_type: https
username: ${GIT_USERNAME}
password: ${GIT_ACCESS_TOKEN}
target_url: https://gitee.com/onlyonexl/vitepress-theme-teek-one-private.git
# git_email: 'github-actions[bot]@users.noreply.github.com'
- name: notify
image: drillster/drone-email
settings:
host: smtp.qq.com # QQ邮箱SMTP服务器
port: 465 # SSL加密端口
username: 2675263825@qq.com # 完整QQ邮箱地址
password: "wuietiubwgrfecgd" # 需使用授权码而非QQ密码
from: 2675263825@qq.com # 发件人邮箱
recipients: # 收件人列表
- 2675263825@qq.com
ssl: true
效果:
方案2
ok-但不够优雅
代码:
master:
push:
- runner:
cpus: 16
services:
- docker
- git-clone-yyds
imports:
- https://cnb.cool/onedayxyy/secret/-/blob/main/envs.yml
docker:
image: docker.cnb.cool/znb/images/node:18
volumes:
- /data/.cache:copy-on-write #声明式的构建缓存
stages:
- name: 🖨️ 打印环境
if: |
[ "$CNB_COMMIT_MESSAGE_TITLE" = "BUILD" ]
script: |
node -v && npm -v && yarn -v && pnpm -v
- name: 📦️ 安装依赖
if: |
[ "$CNB_COMMIT_MESSAGE_TITLE" = "BUILD" ]
script: |
pnpm install
- name: ⚗️ 编译项目
if: |
[ "$CNB_COMMIT_MESSAGE_TITLE" = "BUILD" ]
script: |
pnpm docs:build # VitePress 专用命令
- name: 🚚 发布制品
if: |
[ "$CNB_COMMIT_MESSAGE_TITLE" = "BUILD" ]
image: tencentcom/rsync
settings:
user: ${SSH_USER}
key: ${SSH_KEY}
port: 22
hosts:
- ${ECS_IP}
source: docs/.vitepress/dist/
target: /root/rsync/rsync-vitepress/dist/
delete: true
prescript:
- echo "prescript"
- ls -l /root/rsync/rsync-vitepress/dist/
# script:
# - echo "after script"
# - ls -l /root/rsync/rsync-vitepress/dist/
# - date
# # - bash /root/website_music.sh
# - aliyun cdn RefreshObjectCaches --ObjectType File --ObjectPath "onedayxyy.cn/" #刷新阿里云cdn缓存
# - name: 🔔 发布通知
# image: tencentcom/wecom-message
# settings:
# robot: ${WECOM_BOT}
# msgType: markdown
# content: |
# > **🎉 JenkinsGuide 又一次发布啦!**
# > **构建时间:** $CUSTOM_ENV_DATE_INFO
# > **提交信息:** $CNB_COMMIT_MESSAGE_TITLE
# > **仓库地址:** [$CNB_REPO_URL_HTTPS]($CNB_REPO_URL_HTTPS)
- name: 🧘♂️ 刷新缓存
image: docker.cnb.cool/znb/cdn-refresh
settings:
ak: "${TENCENT_OPSRE_AK}"
sk: "${TENCENT_OPSRE_SK}"
kind: "tencenteo"
rtype: "path"
domain: "onedayxyy.cn"
urls:
- "https://onedayxyy.cn/"
#同步仓库到gitee
- name: sync to gitee
image: tencentcom/git-sync
settings:
branch: master
auth_type: https
username: ${GIT_USERNAME}
password: ${GIT_ACCESS_TOKEN}
target_url: https://gitee.com/onlyonexl/vitepress-theme-teek-one-private.git
# git_email: 'github-actions[bot]@users.noreply.github.com'
- name: notify
image: drillster/drone-email
settings:
host: smtp.qq.com # QQ邮箱SMTP服务器
port: 465 # SSL加密端口
username: 2675263825@qq.com # 完整QQ邮箱地址
password: "wuietiubwgrfecgd" # 需使用授权码而非QQ密码
from: 2675263825@qq.com # 发件人邮箱
recipients: # 收件人列表
- 2675263825@qq.com
ssl: true
subject: "构建通知: {{ repo.name }} #{{ build.number }}"
body: |
项目: {{ repo.name }}
状态: {{ build.status }}
详情: {{ build.link }}
效果:
方案3-企业微信机器人❤️(推荐)
参考:
可以先拉一个微信好友,创建群聊,在剔除好友,就可以可哦。😊
- 创建群机器人
获取自己的群机器人id:
https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
- 最终代码:
.cnb.yml
master:
push:
- runner:
cpus: 16
services:
- docker
- git-clone-yyds
imports:
- https://cnb.cool/onedayxyy/secret/-/blob/main/envs.yml
docker:
image: docker.cnb.cool/znb/images/node:18
volumes:
- /data/.cache:copy-on-write #声明式的构建缓存
stages:
- name: set env
script: echo -n $(date "+%Y-%m-%d %H:%M")
exports:
info: CUSTOM_ENV_DATE_INFO
- name: 🖨️ 打印环境
if: |
[ "$CNB_COMMIT_MESSAGE_TITLE" = "BUILD" ]
script: |
node -v && npm -v && yarn -v && pnpm -v
- name: 📦️ 安装依赖
if: |
[ "$CNB_COMMIT_MESSAGE_TITLE" = "BUILD" ]
script: |
pnpm install
- name: ⚗️ 编译项目
if: |
[ "$CNB_COMMIT_MESSAGE_TITLE" = "BUILD" ]
script: |
pnpm docs:build # VitePress 专用命令
- name: 🚚 发布制品
if: |
[ "$CNB_COMMIT_MESSAGE_TITLE" = "BUILD" ]
image: tencentcom/rsync
settings:
user: ${SSH_USER}
key: ${SSH_KEY}
port: 22
hosts:
- ${ECS_IP}
source: docs/.vitepress/dist/
target: /root/rsync/rsync-vitepress/dist/
delete: true
prescript:
- echo "prescript"
- ls -l /root/rsync/rsync-vitepress/dist/
# script:
# - echo "after script"
# - ls -l /root/rsync/rsync-vitepress/dist/
# - date
# # - bash /root/website_music.sh
# - aliyun cdn RefreshObjectCaches --ObjectType File --ObjectPath "onedayxyy.cn/" #刷新阿里云cdn缓存
- name: 🧘♂️ 刷新缓存
image: docker.cnb.cool/znb/cdn-refresh
settings:
ak: "${TENCENT_OPSRE_AK}"
sk: "${TENCENT_OPSRE_SK}"
kind: "tencenteo"
rtype: "path"
domain: "onedayxyy.cn"
urls:
- "https://onedayxyy.cn/"
#同步仓库到gitee
- name: sync to gitee
image: tencentcom/git-sync
settings:
branch: master
auth_type: https
username: ${GIT_USERNAME}
password: ${GIT_ACCESS_TOKEN}
target_url: https://gitee.com/onlyonexl/vitepress-theme-teek-one-private.git
# git_email: 'github-actions[bot]@users.noreply.github.com'
- name: 🔔 发布通知
image: tencentcom/wecom-message
settings:
robot: ${WECOM_BOT}
msgType: markdown
content: |
> **🎉 One Blog 又一次发布成功啦!**
> **构建时间:** $CUSTOM_ENV_DATE_INFO
> **构建id:** $CNB_BUILD_ID
> **提交id:** $CNB_COMMIT_SHORT
> **构建分支:** $CNB_BRANCH
> **提交信息:** $CNB_COMMIT_MESSAGE_TITLE
> **提交者:** $CNB_COMMITTER
> **仓库地址:** [$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
最后
如果你还有疑惑,可以去我的网站查看更多内容或者联系我帮忙查看。
如果你有更好的方式,评论区留言告诉我。谢谢!
好了,本次就到这里了,感谢大家阅读,最后祝大家生活快乐,每天都过的有意义哦,我们下期见!