當有需求要在k8s上透過drone定期跑godog進行BDD測試,並將測試結果推送到mattermost時,怎麼辦呢?
首先需求拆解:
在BDD專案內,製作你的pipeline
以下以Drone為範例
kind: pipeline
type: kubernetes
name: bdd
steps:
- name: godog solo basic.feature
image: rain123473/godog:v0.11.0
commands:
- cd solo
- godog run features/basic.feature
- name: send notification
when:
status:
- success
image: plugins/slack
settings:
webhook:
from_secret: bdd
channel: ithome-bdd
username: drone
icon_url: https://img.icons8.com/color/2x/good-pincode.png
template: >
[DEV] BDD test build {{build.link}} succeeded. Good job.
- name: send failure notification
when:
status:
- failure
image: plugins/slack
settings:
webhook:
from_secret: bdd
channel: ithome-bdd
username: drone
icon_url: https://img.icons8.com/color/2x/high-priority.png
template: >
{{#success build.status}}
[DEV] BDD test build {{build.link}} succeeded. Good job.
{{else}}
[DEV] BDD build {{build.link}} failed. Fix me please.
{{/success}}
在drone yaml設定,可以使用
when:
status:
來綁定此step的狀態,所以可以從step
看得出來唷!
再次提醒一下
Cron Jobs 的時區是依照 UTC(Universal Time Coordinated),所以需要自己在轉換一下時間
若你的需求是要台灣時間22:00~04:00,每小時觸發的話,不能打22-04
唷!要改成14-20
才正確!
drone cron add "my/bdd-repo" "bdd-nighty-test" "0 0 14-20 * * *" --branch master
之後就能在Mattermost該channel內看到效果囉
---
以上就完成上述之需求(在k8s上透過drone定期跑godog進行BDD測試,並將測試結果推送到mattermost)了,今天就這樣子拉~