iT邦幫忙

第 12 屆 iThome 鐵人賽

DAY 27
0
DevOps

遠離 DevOops系列 第 27

[Day 27] Oops!CI/CD trigger WebHook to Telegram Bot

前言

有時候我們在CI/CD流程進行中時,通常都是被動告知的,那如果想要透過Pipeline主動告知要怎麼做呢?/images/emoticon/emoticon06.gif

我們在第六天[Day 6] Oops!Gitea - WebHook有介紹到Gitea搭配WebHook的做法,而如果要在CI/CD上觸發WebHook去通知Telegram要怎麼做呢?

Telegram Bot API

首先讓我們來瞧瞧Telegram Bot API,Telegram Bot提供API可以直接打Telegram Bot API發送訊息到指定的聊天室

https://api.telegram.org/bot${token}/sendMessage?chat_id=${chat_id}&text=${message}

透過 curl

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〗【鐵人賽】 發文動作開始!!

Telegram 跳出

https://ithelp.ithome.com.tw/upload/images/20201005/20115289Y016sLjm4I.png

透過 Drone Plugin

從Drone Plugin可以找到很多套件,可以搭配CI/CD使用,而我從這找到Telegram by appleboy的套件。
https://ithelp.ithome.com.tw/upload/images/20201005/20115289F93CDzjh81.png

CI/CD for Drone with Drone Plugin

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〗【鐵人賽】 發文動作開始!!"

Telegram 跳出

https://ithelp.ithome.com.tw/upload/images/20201005/20115289o3sjmAOxyB.png

今日小結

大家可以利用CI/CD的Plugin來幫助你們在CI/CD的流程更加完整,有空也不妨去Plugin網站上逛逛吧~/images/emoticon/emoticon07.gif


上一篇
[Day 26] Oops!GitOps with Helm
下一篇
[Day 28] Oops!Golang - Google Cloud Status Monitor with Telegram
系列文
遠離 DevOops30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言