LoginSignup
4
6

More than 3 years have passed since last update.

Github Actionsのスクリプトでgit commitする時に更新がなかった場合エラー(Process completed with exit code 1.)が出る問題の対処法

Last updated at Posted at 2020-05-29

例えば下記の様なスクリプトがあった場合、何もgitレポに更新がないと、git commit -m "By Yamada Taro"だけだとProcess completed with exit code 1.が出てしまう。

エラーが出て見栄えが悪いだけで、別になんの問題もないようですが、

git commit -m "By Yamada Taro" || echo "No changes to commit"

と、||でエラーをキャッチしてあげることで、エラーが記録されなくなりサッパリとします。

# This is a basic workflow to help you get started with Actions

name: 適当な名前

# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch
on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  # This workflow contains a single job called "build"
  build:
    # The type of runner that the job will run on
    runs-on: ubuntu-latest

    # Steps represent a sequence of tasks that will be executed as part of the job
    steps:

    - uses: actions/checkout@v2

    - name: Cache node modules
      uses: actions/cache@v1
      env:
        cache-name: cache-node-modules
      with:
        # npm cache files are stored in `~/.npm` on Linux/macOS
        path: ~/.npm
        key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
        restore-keys: |
          ${{ runner.os }}-build-${{ env.cache-name }}-
          ${{ runner.os }}-build-
          ${{ runner.os }}-

    - name: Install NPM dependencies
      run: npm install

    - name: Run Script
      run: npm run dosomething

    - name: Push any changes to the Git repo
      run: |
        git config user.email "info@yamada-tarou.com"
        git config user.name "山田太郎"
        git push origin HEAD:master
        git add .
        git commit -m "By Yamada Taro" || echo "No changes to commit"
        git push

参考にしたページ:How to let Jenkins git commit only if there are changes?

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