How to handle appcenter login error in shell script?

298 views Asked by At

I am using the below script for publishing the ipa to appcenter.

ipaPath=<PATH TO MY IPA FILE>
echo "Found ipa at $ipaPath"

if [[ -z ${ipaPath} ]]

then

    echo "No ipas were found, skip publishing to App Center"

else

    appcenter login 
    appcenter distribute release \
        --group Collaborators \
        --file "${ipaPath}" \
        --release-notes 'App submission' \
        --app <username_or_organization>/<application_identifier> \
        --quiet
fi

I need to exit if the login is failed and don't want to run the distribute command. how to check the login status and handle the error?

1

There are 1 answers

2
RGB World On

You could use command substitution to capture the result of appcenter login into a variable, then search the variable contents for a specific string (or lack of). For example:

reply="$(appcenter login --token ${token})"

if [[ $reply == *"Error"* ]]; then
  echo "A problem occurred! ${reply}"
else
  appcenter distribute release
  ...
fi