23 Oct 2023

Gitlab Pipeline Push to Git Without Tears

Gitlab pipeline becomes really sad if you have a job in your pipeline were you blindly push some crap into a repo “just in case”, but it turns out there are no changes, signaling “Everything up-to-date” and faults the pipeline with exit code 1.

There is however a clever way to solve this:

git diff returns 0 if no changes are made. So it wont run git commit and git push. If git diff returns 1, we have happy times.

git diff --quiet && git diff --staged --quiet || git commit -m "Finally a change" && git push