LoginSignup
38
6

More than 1 year has passed since last update.

GitHub Actions にタイムアウトを設定しておいた方が良い

Last updated at Posted at 2021-12-10

はじめに

こちらの記事は GitHub Actions Advent Calendar 2021 の11日目の記事です。他の皆様の投稿もぜひご覧ください!

この記事では、GitHub Actions のジョブのタイムアウトの設定の仕方を紹介していきます。

ジョブのタイムアウトのデフォルト

GitHub Actions のジョブのタイムアウトの時間は、デフォルトで6時間です。

Job execution time - Each job in a workflow can run for up to 6 hours of execution time. If a job reaches this limit, the job is terminated and fails to complete.

参考: https://docs.github.com/ja/actions/learn-github-actions/usage-limits-billing-and-administration#usage-limits

なんらかの原因でワークフローの実行が失敗もせずに止まってしまうことはどうしても起こると思うのですが、その際に気づかなかった場合(&タイムアウトの時間がデフォルトのままだった場合)、6時間も時間を消費してしまいます。

夜中に動かしているものだとなかなか気付きませんよね。私はタイムアウトのデフォルトが6時間ということを認識しておらず、朝ワークフローが失敗しているログを見て「360 minutes !?」となりました・・・。

タイムアウトの設定方法

ジョブに対してと、各step個別に対しての、2つの方法でタイムアウトを設定できます。

ジョブに対して

参考: https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#jobsjob_idtimeout-minutes

jobs:
  my-job:
    runs-on: ubuntu-latest
    timeout-minutes: 60
    steps:
      - name: print log
        run: echo "Hello, GitHub Actions"

stepに対して

参考: https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#jobsjob_idstepstimeout-minutes

jobs:
  my-job:
    runs-on: ubuntu-latest
    steps:
      - name: print log
        run: echo "Hello, GitHub Actions"
        timeout-minutes: 5
      - name: print log 2
        run: echo "Hello, GitHub Actions 2"
        timeout-minutes: 10

最後に

まずはジョブ毎に普段の実行時間 + α でつければ良いだけなので、まだつけていないという方はつけるのをおすすめします。

38
6
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
38
6