How to let Jenkins git commit only if there are changes?
To stop the build from breaking on the shell build step returning exit code 1
at any one point, e.g., when trying to make a git commit although there is nothing to commit, you can simply wrap the respective commands into an echo.
echo `git add -A && git commit -m "Added license headers"`
Now, whether there are untracked files to add to the index or not, and whether the working tree is dirty or clean, echo will return exit code 0
, as there will be some string to be echo
ed.