'Prevent Gitlab pipeline fail when nothing to commit

I had realized this pipeline

send:
  image: node:latest
  before_script:
    - git config --global user.email "[email protected]"
    - git config --global user.name "Gitlab CI"
  script:
    - npm install
    - npm run start $GMAIL_PW
    - echo "Committing updated files to git"

    - git add executions.txt
    - git commit -m "Updated executions with new running date"
    - git push "https://${GITLAB_USER_NAME}:${CI_ACCESS_TOKEN}@${CI_REPOSITORY_URL#*@}" "HEAD:${CI_COMMIT_REF_NAME}" -o skip-ci
  only:
    - schedules

Sometimes there is nothing to commit and the pipeline fails with this error

$ git add executions.txt
$ git commit -m "Updated executions with new running date"
HEAD detached at 0fa2f4d
nothing to commit, working tree clean
Cleaning up project directory and file based variables
00:00
ERROR: Job failed: exit code 1

How I can prevent the pipeline to fail when there is nothing to commit?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source