ある日突然、GitHub Actionsで定期実行しているジョブが失敗するようになりました。その際に、GitHub Actionsのデバッグログ機能を活用して原因を調査したので、その内容をご紹介します。
エラーログを確認すると、以下のようなメッセージが出力されていました。
##[error]The runner has received a shutdown signal. This can happen when the runner service is stopped, or a manually started runner is canceled.
················ ELIFECYCLE Command failed.
##[error]The operation was canceled.
このログだけでは、ランナーがシャットダウン信号を受け取ったことは分かりますが、なぜそうなったのか、具体的な原因を特定するのは困難です。
失敗したジョブのログを見ても、これ以上の情報は得られませんでした。
このような状況で役立つのが、GitHub Actionsの デバッグログ機能 です。デバッグログを有効にすると、ワークフローの実行に関するより詳細な情報が出力され、問題の原因究明に繋がる手がかりを得やすくなります。
デバッグログを有効にする方法は非常に簡単です。
ACTIONS_RUNNER_DEBUG
true
これで設定は完了です。この状態で再度ワークフローを実行すると、詳細なログが出力されるようになります。
実際にデバッグログを有効にしてワークフローを再実行したところ、ログの出力が大幅に増加しました。
ログには ##[debug]
というプレフィックスが付いた行が多数追加され、各ステップの内部的な動作やAPIコール、環境変数はマスク付きで記録されています。
················ ELIFECYCLE Command failed.
Error: The operation was canceled.
##[debug]System.OperationCanceledException: The operation was canceled.
##[debug] at System.Threading.CancellationToken.ThrowOperationCanceledException()
##[debug] at GitHub.Runner.Sdk.ProcessInvoker.ExecuteAsync(String workingDirectory, String fileName, String arguments, IDictionary`2 environment, Boolean requireExitCodeZero, Encoding outputEncoding, Boolean killProcessOnCancel, Channel`1 redirectStandardIn, Boolean inheritConsoleHandler, Boolean keepStandardInOpen, Boolean highPriorityProcess, CancellationToken cancellationToken)
##[debug] at GitHub.Runner.Common.ProcessInvokerWrapper.ExecuteAsync(String workingDirectory, String fileName, String arguments, IDictionary`2 environment, Boolean requireExitCodeZero, Encoding outputEncoding, Boolean killProcessOnCancel, Channel`1 redirectStandardIn, Boolean inheritConsoleHandler, Boolean keepStandardInOpen, Boolean highPriorityProcess, CancellationToken cancellationToken)
##[debug] at GitHub.Runner.Worker.Handlers.DefaultStepHost.ExecuteAsync(IExecutionContext context, String workingDirectory, String fileName, String arguments, IDictionary`2 environment, Boolean requireExitCodeZero, Encoding outputEncoding, Boolean killProcessOnCancel, Boolean inheritConsoleHandler, String standardInInput, CancellationToken cancellationToken)
##[debug] at GitHub.Runner.Worker.Handlers.ScriptHandler.RunAsync(ActionRunStage stage)
##[debug] at GitHub.Runner.Worker.ActionRunner.RunAsync()
##[debug] at GitHub.Runner.Worker.StepsRunner.RunStepAsync(IStep step, CancellationToken jobCancellationToken)
##[debug]Finishing: Run e2e tests
これにより、どのコマンドのどのタイミングで予期せぬ動作が発生しているのか、より詳細に追跡することが可能になります。
GitHub Actionsで原因不明のエラーに遭遇した際は、まずデバッグログを有効にすることをお勧めします。ACTIONS_RUNNER_DEBUG
を true
に設定するだけで、問題解決に繋がる多くのヒントを得られる可能性があります。トラブルシューティングの第一歩として、ぜひこの方法を試してみてください。
以上、GitHub Actionsでジョブがキャンセルされるのでデバッグログを有効にして原因を調査した、現場からお送りしました。