diff --git a/gitops/azure-devops/build.sh b/gitops/azure-devops/build.sh index 7026f3a..f550787 100644 --- a/gitops/azure-devops/build.sh +++ b/gitops/azure-devops/build.sh @@ -245,7 +245,8 @@ function git_commit() { # Checks for changes and only commits if there are changes staged. Optionally can be configured to fail if called to commit and no changes are staged. # First arg - commit message -# Second arg - should fail if there is nothing to commit, any non 0 value. +# Second arg - "should error if there is nothing to commit" flag. Set to 0 if this behavior should be skipped and it will not error when there are no changes. +# Third arg - variable to check if changes were commited or not. Will be set to 1 if changes were made, 0 if not. function git_commit_if_changes() { echo "GIT STATUS" @@ -254,13 +255,21 @@ function git_commit_if_changes() { echo "GIT ADD" git add -A - if [[ $(git status --porcelain) ]] || [[ $2 ]]; then + commitSuccess=0 + if [[ $(git status --porcelain) ]] || [ -z "$2" ]; then echo "GIT COMMIT" - git commit -m "Updated k8s manifest files post commit: $1" - retVal=$? && [ $retVal -ne 0 ] && exit $retVal + git commit -m "$1" + retVal=$? + if [[ "$retVal" != "0" ]]; then + echo "ERROR COMMITING CHANGES -- MAYBE: NO CHANGES STAGED" + exit $retVal + fi + commitSuccess=1 else echo "NOTHING TO COMMIT" fi + echo "commitSuccess=$commitSuccess" + printf -v $3 "$commitSuccess" } # Perform a Git push