Skip to content

Commit

Permalink
Merge pull request #48 from buildkite-plugins/bash-3-avoid-mapfile
Browse files Browse the repository at this point in the history
bash 3.x compatibility; avoid mapfile
  • Loading branch information
pda authored Jun 29, 2020
2 parents ef07d7a + 5ac470d commit 06be3a0
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions hooks/environment
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ function retry() {
# 'aws ecr get-login-password' was not available until v1.7.10 which
# was only released earlier that same month.
function login_using_aws_ecr_get_login() {
mapfile -t registry_ids <<< "$(plugin_read_list ACCOUNT_IDS | tr "," "\n")"
# bash 3.x compatible equivalent of mapfile;
# https://github.com/koalaman/shellcheck/wiki/SC2207
registry_ids=()
while IFS='' read -r line; do registry_ids+=("$line"); done < <(plugin_read_list ACCOUNT_IDS | tr "," "\n")

login_args=()

# If not specified, auto-detect if we can support no-include-email
Expand Down Expand Up @@ -125,11 +129,14 @@ function login_using_aws_ecr_get_login_password() {
echo >&2 "AWS region should be specified via plugin config or AWS_DEFAULT_REGION environment."
echo >&2 "Defaulting to $region for legacy compatibility."
fi
mapfile -t account_ids <<< "$(plugin_read_list ACCOUNT_IDS | tr "," "\n")"
if [[ -z ${account_ids[*]} ]]; then
account_ids=()
while IFS='' read -r line; do account_ids+=("$line"); done < <(plugin_read_list ACCOUNT_IDS | tr "," "\n")
# check if account_ids is empty, or only contains an empty string.
# just testing [[ -z ${account_ids[*]} ]] breaks on bash 3.x if the array is empty.
if [[ ${#account_ids[@]} -eq 0 || -z "${account_ids[*]}" ]]; then
account_ids=("$(aws sts get-caller-identity --query Account --output text)")
fi
if [[ -z ${account_ids[*]} ]]; then
if [[ ${#account_ids[@]} -eq 0 || -z "${account_ids[*]}" ]]; then
echo >&2 "AWS account ID required via plugin config or 'aws sts get-caller-identity'"
exit 1
fi
Expand Down

0 comments on commit 06be3a0

Please sign in to comment.