Skip to content

Commit

Permalink
Fix error handling and ENV var scoping
Browse files Browse the repository at this point in the history
  • Loading branch information
liamdawson committed Oct 28, 2020
1 parent 64e9ae4 commit ddbcfca
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions hooks/environment
Original file line number Diff line number Diff line change
Expand Up @@ -157,19 +157,24 @@ function login() {
}

function assume_role_for_ecr_login() {
export "$(aws sts assume-role \
local export_credentials; export_credentials="$(aws sts assume-role \
--role-arn "${BUILDKITE_PLUGIN_ECR_ASSUME_ROLE_ROLE_ARN}" \
--role-session-name "ecr-login-buildkite-plugin" \
--duration-seconds "${BUILDKITE_PLUGIN_ECR_ASSUME_ROLE_DURATION_SECONDS:-3600}" \
--output text \
--query "[['AWS_ACCESS_KEY_ID',Credentials.AccessKeyId],['AWS_SECRET_ACCESS_KEY',Credentials.SecretAccessKey],['AWS_SESSION_TOKEN',Credentials.SessionToken]][*].join(\`=\`,@)")"

#shellcheck disable=SC2086
export ${export_credentials?}
}

# For logging into the current AWS account’s registry
if [[ "${BUILDKITE_PLUGIN_ECR_LOGIN:-}" =~ ^(true|1)$ ]] ; then
if [[ -n "${BUILDKITE_PLUGIN_ECR_ASSUME_ROLE_ROLE_ARN:-}" ]]; then
assume_role_for_ecr_login
fi
(
if [[ -n "${BUILDKITE_PLUGIN_ECR_ASSUME_ROLE_ROLE_ARN:-}" ]]; then
assume_role_for_ecr_login
fi

login
login
)
fi

0 comments on commit ddbcfca

Please sign in to comment.