diff --git a/bx_login.sh b/bx_login.sh index a12a563..b00f042 100755 --- a/bx_login.sh +++ b/bx_login.sh @@ -7,15 +7,24 @@ if [ -z $CF_SPACE ]; then CF_SPACE="$BLUEMIX_SPACE" fi - -if [ -z "$BLUEMIX_USER" ] || [ -z "$BLUEMIX_PASSWORD" ] || [ -z "$BLUEMIX_ACCOUNT" ]; then +#Check for api key or PW +if [[ -z "$BLUEMIX_USER" || -z "$BLUEMIX_PASSWORD" || -z "$BLUEMIX_ACCOUNT" ]] && [ -z "$BLUEMIX_API_KEY" ]; then echo "Define all required environment variables and rerun the stage." exit 1 fi echo "Deploy pods" echo "bx login -a $CF_TARGET_URL" -bx login -a "$CF_TARGET_URL" -u "$BLUEMIX_USER" -p "$BLUEMIX_PASSWORD" -c "$BLUEMIX_ACCOUNT" -o "$CF_ORG" -s "$CF_SPACE" + +# Use API_KEY if exists +if [ -n "$BLUMEIX_API_KEY" ]; then + echo "Logging in with API key" + bx login -a "$CF_TARGET_URL" --apikey "$BLUEMIX_API_KEY" -o "$CF_ORG" -s "$CF_SPACE" +else + echo "Logging in with user credentials" + bx login -a "$CF_TARGET_URL" -u "$BLUEMIX_USER" -p "$BLUEMIX_PASSWORD" -c "$BLUEMIX_ACCOUNT" -o "$CF_ORG" -s "$CF_SPACE" +fi + if [ $? -ne 0 ]; then echo "Failed to authenticate to Bluemix" exit 1