GitHub Actions: Job failed
GitHub Actionsのジョブが失敗した場合の原因調査と解決策
概要
GitHub Actionsのワークフロージョブが失敗した際の調査と解決方法です。
エラーメッセージ
``` Error: Process completed with exit code 1. ```
原因
- テストの失敗: ユニットテストやE2Eテストの失敗
- 依存関係の問題: npm install等の失敗
- 環境変数の欠落: secrets未設定
- タイムアウト: ジョブの実行時間超過
解決策
1. ログを詳しく確認
```yaml
- name: Run tests run: npm test env: CI: true DEBUG: ‘*’ # デバッグログを有効化 ```
2. キャッシュを活用
```yaml
name: Cache node modules uses: actions/cache@v4 with: path: ~/.npm key: ${{ runner.os }}-node-${{ hashFiles(’**/package-lock.json’) }} restore-keys: | ${{ runner.os }}-node-
name: Install dependencies run: npm ci ```
3. Secretsを設定
```yaml
- name: Deploy run: ./deploy.sh env: AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} ```
4. タイムアウトを設定
```yaml jobs: test: runs-on: ubuntu-latest timeout-minutes: 30 steps: - uses: actions/checkout@v4 - name: Run slow tests timeout-minutes: 10 run: npm test ```
5. 失敗時のデバッグ
```yaml
name: Upload test results on failure if: failure() uses: actions/upload-artifact@v4 with: name: test-results path: test-results/
name: Debug with tmate if: failure() uses: mxschmitt/action-tmate@v3 timeout-minutes: 15 ```
6. マトリックスビルド
```yaml strategy: fail-fast: false # 1つ失敗しても他は継続 matrix: node-version: [16, 18, 20] os: [ubuntu-latest, windows-latest] ```
よくある間違い
- secretsの名前のタイプミス
- actions/checkout を忘れる
- working-directory の指定忘れ
関連エラー
関連エラー
CI/CD の他のエラー
この記事は役に立ちましたか?