2
1

More than 3 years have passed since last update.

GitHub Actions APIでJobを再実行する

Last updated at Posted at 2020-06-03

GitHub ActionsのAPIを利用してJobを再実行する方法を解説します。

手順としては

  1. アクセストークンを発行する
  2. cURLコマンドでURLへPOSTする

になります。

実際に動いているリポジトリはこちらです。

このエントリーの意図

GitHub Actions APIでWorkflow rerunが動かない人向けです。Workflow runs | GitHub Developer Guide

アクセストークンを発行する

プロフィールアイコン」→「Settings」→「Developer settings」→「Personal access tokens」→「Generate new token

スクリーンショット 2020-06-03 21.55.32.png
スクリーンショット 2020-06-03 21.58.40.png
スクリーンショット 2020-06-03 22.00.53.png
repo」と「workflow」にチェックを入れ「Generate token」をクリックする
スクリーンショット 2020-06-03 22.08.37.png
スクリーンショット 2020-06-03 22.09.18.png
スクリーンショット 2020-06-03 22.06.18.png

GitHub Actionsを実行するファイル

「on」エレメントに「deployment」を指定します。push時にもWorkflowを実行したい場合は両方記述しておきます。

.github/workflows/test.yml
---
name: trailing whitespace
on: [deployment, push]

jobs:
  trailing-whitespace:
    name: Find Trailing Whitespace
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: harupy/find-trailing-whitespace@master

Workflowを再実行する

以下のコマンドで実行します。

curl -X POST \
  -H "Authorization: token xxxxxxxxxxxxxxxx" \
  -d '{"ref": "master", "environment": "periodic execution"}' \
  https://api.github.com/repos/${username}/${reponame}/deployments

コマンドの詳しいオプションはDeployments | GitHub Developer Guideで確認する事ができます。

参考サイト

2
1
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
2
1