LoginSignup
11
7

More than 3 years have passed since last update.

GitHub Actionsを定期実行して結果をSlackに通知する

Posted at

やりたいこと

  • E2Eテストなど定期的に実行したいやつをGitHub Actionsでやりたい
  • 実行結果をSlackに通知したい

GitHub Actions

  • 毎日11時にEchoするActions
  • ブランチの指定がない場合、デフォルトブランチのコードで実行される
  • Slackと連携する際のWebhookはGitHubのSecretsに設定する
cron.yml
name: CRON
on:
  schedule:
  # UTC
  - cron: '0 2 * * *'

jobs:
  hi:
    name: Hi
    runs-on: ubuntu-latest
    steps:
    - name: Check out code
      uses: actions/checkout@v1
      # デフォルトブランチ以外を実行したい場合はブランチを指定する
#      with:
#        ref: other
    - name: Echo
      run: echo "I've checked out"
    - name: Slack Notification
      # 前Stepの実行結果を判定
      # success() or failure() or always()
      if: always()
      uses: rtCamp/action-slack-notify@master
      env:
        SLACK_CHANNEL: channel_name
        SLACK_ICON: https://github.com/rtCamp.png?size=48
        SLACK_MESSAGE: 'Post Content :rocket:'
        SLACK_TITLE: Post Title
        SLACK_USERNAME: rtCamp
        SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}

所感

  • 定期的に実行する系のやつはGitHub Actionsで事足りそう

GitHub

11
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
7