我們在第六天[Day 6] Oops!Gitea - WebHook有介紹到Gitea搭配WebHook的做法,而如果要在CI/CD上觸發WebHook去通知Telegram要怎麼做呢?
首先讓我們來瞧瞧Telegram Bot API,Telegram Bot提供API可以直接打Telegram Bot API發送訊息到指定的聊天室
https://api.telegram.org/bot${token}/sendMessage?chat_id=${chat_id}&text=${message}
exmaple for drone
kind: pipeline
type: docker
name: linter
steps:
- name: alert_production_ci
detach: true
when:
branch: master
image: rain123473/alpine-curl:3.11.6
commands:
- curl https://api.telegram.org/bot${token}/sendMessage?chat_id=${chat_id}&text=【溫馨提醒】〖ITHOME〗【鐵人賽】 發文動作開始!!
從Drone Plugin可以找到很多套件,可以搭配CI/CD使用,而我從這找到Telegram by appleboy的套件。
exmaple for drone yaml
kind: pipeline
type: docker
name: ithome_telegram_webhook
steps:
- name: ithome_alert
image: appleboy/drone-telegram:1.3.8
settings:
token:
from_secret: telegram_token
to:
from_secret: telegram_to
message: "【溫馨提醒】〖ITHOME〗【鐵人賽】 發文動作開始!!"
大家可以利用CI/CD的Plugin來幫助你們在CI/CD的流程更加完整,有空也不妨去Plugin網站上逛逛吧~