github的action提供了持续集成和持续交付的能力。
想在action流程失败时给予告警,github默认提供的方式是可以推送给邮箱。不过大部分人对于邮件的响应速度应该不会太快。所以在action step设置错误告警,则是比较方便快捷了。
默认情况下action 会扫描所有的step,错误则跳过,可以在stage 最后的step里面设置捕获错误
捕获方式:if: ${{ failure() }}
例:
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3
# Runs a single command using the runners shell
- name: Run a one-line script
run: echo Hello, world!
- name: Step1
run: |
echo "${{ github.repository }}"
echo "${{ github.head_ref }}"
- name: Step2
run: |
go run main.go
- name: Step3
run: |
echo 2222
- name: Step4 //设置对应的告警
if: ${{ failure() }}
run: |
author=$(git show -s --format=%an)
curl --location --request POST xxxx
如上述代码所示,我们在Step2特意执行报错(没有main.go文件),则Step3会跳过,最终Step4判断出错了,则执行curl(想要的告警)