From bc765bd1922c8da8a21cf341eb0409113688dd37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20A=2E=20Bellone?= <matias.bellone@buildkite.com> Date: Fri, 13 Jan 2023 11:21:29 -0300 Subject: [PATCH 1/2] Had loop inside conditional to avoid dereferencing an empty array --- hooks/pre-exit | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/hooks/pre-exit b/hooks/pre-exit index 8a4887b..6077d07 100755 --- a/hooks/pre-exit +++ b/hooks/pre-exit @@ -108,11 +108,12 @@ if [[ "${#matching_files[@]}" -eq "0" ]]; then if [[ -z "${BUILDKITE_COMMAND_EXIT_STATUS+x}" ]] || [[ "${BUILDKITE_COMMAND_EXIT_STATUS}" -eq "0" ]]; then exit 1 fi -fi - -for file in "${matching_files[@]}"; do - echo "Uploading '$file'..." - if ! upload "$TOKEN_VALUE" "$FORMAT" "${file}"; then - echo "Error uploading, will continue" - fi -done +else + # needs to be part of else for bash4.3 compatibility + for file in "${matching_files[@]}"; do + echo "Uploading '$file'..." + if ! upload "$TOKEN_VALUE" "$FORMAT" "${file}"; then + echo "Error uploading, will continue" + fi + done +fi \ No newline at end of file From 9a30ad6225896c9de5fcd43f42a9922dc9d3cdbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20A=2E=20Bellone?= <matias.bellone@buildkite.com> Date: Fri, 13 Jan 2023 11:21:44 -0300 Subject: [PATCH 2/2] Simplified condition --- hooks/pre-exit | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hooks/pre-exit b/hooks/pre-exit index 6077d07..6c5be71 100755 --- a/hooks/pre-exit +++ b/hooks/pre-exit @@ -105,7 +105,7 @@ done < <("${FIND_CMD[@]}" . -path "./${FILES_PATTERN}") if [[ "${#matching_files[@]}" -eq "0" ]]; then echo "No files found matching '${FILES_PATTERN}'" - if [[ -z "${BUILDKITE_COMMAND_EXIT_STATUS+x}" ]] || [[ "${BUILDKITE_COMMAND_EXIT_STATUS}" -eq "0" ]]; then + if [[ "${BUILDKITE_COMMAND_EXIT_STATUS:-0}" -eq "0" ]]; then exit 1 fi else