GitLab + pushplus:仓库事件与 CI 失败通知
效果:流水线失败或仓库事件发生时,微信收到通知。动态内容用 CI job;固定文案可用 Webhook URL。
前置条件
- 一个 pushplus token(官网扫码获取)
- GitLab 项目 Maintainer 或可改
.gitlab-ci.yml的权限
方式一:CI 动态内容(推荐)
在 GitLab 项目 Settings → CI/CD → Variables 添加 PUSHPLUS_TOKEN(Masked、Protected 按需)。
notify:
stage: .post
script:
- |
curl -s -X POST "https://www.pushplus.plus/send" \
-H "Content-Type: application/json" \
-d "{\"token\":\"$PUSHPLUS_TOKEN\",\"title\":\"GitLab CI $CI_PROJECT_PATH\",\"content\":\"job=$CI_JOB_NAME\\nref=$CI_COMMIT_REF_NAME\\nstatus=$CI_JOB_STATUS\\nurl=$CI_PIPELINE_URL\",\"template\":\"markdown\"}"
rules:
- when: on_failure
变量名以 GitLab 预定义为准,可把提交说明拼进 content。
方式二:Webhook 固定文案
仓库 Settings → Webhooks,URL 填:
https://www.pushplus.plus/send?token=你的token&title=GitLab有新事件&content=请打开GitLab查看
勾选需要的事件(Push、Merge Request、Pipeline)。GitLab POST 的 JSON 不会自动变成正文,此方式只有固定文案。
验证
curl -X POST "https://www.pushplus.plus/send" \
-H "Content-Type: application/json" \
-d '{"token":"你的token","title":"GitLab 配置测试","content":"token 可用","template":"markdown"}'
常见问题
Webhook 点了 Test 没内容细节? 这是预期行为。要分支名、流水线状态请用方式一。
Runner 里 curl 失败? 确认 Runner 能访问外网 www.pushplus.plus。