例えば下記の様なスクリプトがあった場合、何も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?