golang通过Drone CI发送Line通知插件库drone-line的使用
Golang通过Drone CI发送Line通知插件库drone-line的使用
drone-line简介
drone-line是一个用于发送Line通知的工具,可以通过二进制文件、Docker容器或Drone CI来使用。
功能特性
- 发送多种消息类型
- 文本消息
- 视频消息
- 音频消息
- 贴纸消息
- 位置消息
- 支持Prometheus指标API
- 自动从Let’s Encrypt安装TLS证书
- 支持Localtunnel进行webhook隧道
- 支持Line Notify服务
安装方式
二进制安装
预编译的二进制文件可以从release页面下载,支持以下操作系统:
- Windows amd64/386
- Linux amd64/386
- Darwin amd64/386
使用Go安装:
go get -u -v github.com/appleboy/drone-line
或者自行编译:
make build
Docker安装
构建Docker镜像:
make docker
使用方法
二进制使用
设置Webhook服务
默认端口8088:
drone-line \
--secret xxxx \
--token xxxx \
webhook
更改端口到8089:
drone-line \
--port 8089 \
--secret xxxx \
--token xxxx \
webhook
使用Localtunnel:
drone-line \
-s secret \
-t token \
--tunnel \
--port 2002 \
webhook
使用Let’s Encrypt:
drone-line \
-s secret \
-t token \
-autotls \
-host example.com \
-cache /var/www/.cache \
--port 443 \
webhook
发送通知
drone-line \
--secret xxxx \
--token xxxx \
--to xxxx \
--message "Test Message"
发送LINE Notify
drone-line \
--token xxxx \
--message "Test Message" \
notify
Docker使用
设置Webhook服务
默认端口8088:
docker run --rm \
-e LINE_CHANNEL_SECRET=xxxxxxx \
-e LINE_CHANNEL_TOKEN=xxxxxxx \
appleboy/drone-line webhook
更改端口到8089:
docker run --rm \
-e LINE_CHANNEL_SECRET=xxxxxxx \
-e LINE_CHANNEL_TOKEN=xxxxxxx \
-e LINE_PORT=8089 \
appleboy/drone-line webhook
发送通知
docker run --rm \
-e LINE_CHANNEL_SECRET=xxxxxxx \
-e LINE_CHANNEL_TOKEN=xxxxxxx \
-e LINE_TO=xxxxxxx \
-e LINE_MESSAGE=test \
-e LINE_IMAGES=https://example.com/1.png \
-e LINE_VIDEOS=https://example.com/1.mp4 \
-e LINE_AUDIOS=https://example.com/1.mp3::1000 \
-e LINE_STICKERS=1::1 \
-e LINE_LOCATIONS=title::address::latitude::longitude \
-e LINE_DELIMITER=:: \
appleboy/drone-line
Drone CI使用
docker run --rm \
-e PLUGIN_CHANNEL_SECRET=xxxxxxx \
-e PLUGIN_CHANNEL_TOKEN=xxxxxxx \
-e PLUGIN_TO=xxxxxxx \
-e PLUGIN_MESSAGE=test \
-e PLUGIN_IMAGES=https://example.com/1.png \
-e PLUGIN_VIDEOS=https://example.com/1.mp4 \
-e PLUGIN_AUDIOS=https://example.com/1.mp3::1000 \
-e PLUGIN_STICKERS=1::1 \
-e PLUGIN_LOCATIONS=title::address::latitude::longitude \
-e PLUGIN_DELIMITER=:: \
-e PLUGIN_ONLY_MATCH_EMAIL=false \
-e DRONE_REPO_OWNER=appleboy \
-e DRONE_REPO_NAME=go-hello \
-e DRONE_COMMIT_SHA=e5e82b5eb3737205c25955dcc3dcacc839b7be52 \
-e DRONE_COMMIT_BRANCH=master \
-e DRONE_COMMIT_AUTHOR=appleboy \
-e DRONE_COMMIT_AUTHOR_EMAIL=appleboy@gmail.com \
-e DRONE_COMMIT_MESSAGE=Test_Your_Commit \
-e DRONE_BUILD_NUMBER=1 \
-e DRONE_BUILD_STATUS=success \
-e DRONE_BUILD_LINK=http://github.com/appleboy/go-hello \
-e DRONE_JOB_STARTED=1477550550 \
-e DRONE_JOB_FINISHED=1477550750 \
-v $(pwd):$(pwd) \
-w $(pwd) \
appleboy/drone-line
测试
运行测试:
make test
更多关于golang通过Drone CI发送Line通知插件库drone-line的使用的实战教程也可以访问 https://www.itying.com/category-94-b0.html
1 回复
更多关于golang通过Drone CI发送Line通知插件库drone-line的使用的实战系列教程也可以访问 https://www.itying.com/category-94-b0.html
使用Drone CI发送Line通知的drone-line插件指南
drone-line插件简介
drone-line
是一个专为Drone CI/CD系统设计的插件,用于在构建过程中通过Line Notify服务发送通知消息。这对于团队协作和构建状态监控非常有用。
安装与配置
1. 获取Line Notify访问令牌
首先需要在Line Notify官网(https://notify-bot.line.me/)获取访问令牌:
- 登录Line Notify
- 点击"个人页面"
- 选择"发行令牌"
- 选择要接收通知的聊天室或群组
- 生成并复制令牌
2. 在Drone中配置插件
在.drone.yml
配置文件中添加以下内容:
kind: pipeline
type: docker
name: default
steps:
- name: notify
image: appleboy/drone-line
settings:
access_token:
from_secret: line_token
message: "构建成功: ${DRONE_REPO_NAME} ${DRONE_COMMIT_MESSAGE}"
when:
status:
- success
- failure
详细配置选项
drone-line
插件支持多种配置选项:
steps:
- name: line-notify
image: appleboy/drone-line
settings:
access_token:
from_secret: line_token # 从Drone secrets获取的Line Notify令牌
message: "自定义消息内容" # 发送的消息内容
image_thumbnail: # 缩略图URL
image_fullsize: # 完整大小图片URL
sticker_package_id: # 贴纸包ID
sticker_id: # 贴纸ID
debug: false # 调试模式
完整示例
下面是一个完整的.drone.yml
示例,包含构建、测试和通知步骤:
kind: pipeline
type: docker
name: default
steps:
- name: build
image: golang:1.20
commands:
- go build -v ./...
- name: test
image: golang:1.20
commands:
- go test -v ./...
- name: notify-success
image: appleboy/drone-line
settings:
access_token:
from_secret: line_token
message: |
构建成功 🎉
仓库: ${DRONE_REPO_NAME}
分支: ${DRONE_BRANCH}
提交: ${DRONE_COMMIT_MESSAGE}
详情: ${DRONE_BUILD_LINK}
when:
status:
- success
- name: notify-failure
image: appleboy/drone-line
settings:
access_token:
from_secret: line_token
message: |
构建失败 ❌
仓库: ${DRONE_REPO_NAME}
分支: ${DRONE_BRANCH}
提交: ${DRONE_COMMIT_MESSAGE}
详情: ${DRONE_BUILD_LINK}
sticker_package_id: 2
sticker_id: 34
when:
status:
- failure
高级用法
使用模板消息
- name: notify
image: appleboy/drone-line
settings:
access_token:
from_secret: line_token
message: |
{{#success build.status}}
✅ 构建成功
{{else}}
❌ 构建失败
{{/success}}
项目: {{repo.name}}
分支: {{build.branch}}
提交: {{build.message}}
详情: {{build.link}}
发送图片通知
- name: notify-with-image
image: appleboy/drone-line
settings:
access_token:
from_secret: line_token
message: "构建完成截图"
image_thumbnail: "https://example.com/thumbnail.jpg"
image_fullsize: "https://example.com/fullsize.jpg"
安全注意事项
- 永远不要将Line Notify令牌直接写在配置文件中
- 使用Drone的secrets功能存储敏感信息
- 为不同的环境使用不同的令牌
- 定期轮换令牌
故障排除
如果通知没有发送,可以:
- 检查Drone的日志输出
- 确保令牌有正确的权限
- 验证网络连接是否允许访问Line Notify API
- 启用调试模式查看详细日志
settings:
debug: true
通过以上配置,您可以在Drone CI/CD流程中轻松集成Line通知功能,及时了解构建状态。