From 7b2b62d1e3969f27bf116617ba904d395198d266 Mon Sep 17 00:00:00 2001 From: David Kale Date: Thu, 8 Feb 2018 15:48:32 -0500 Subject: [PATCH] Update error handling for invalid PAT token (#71) * Update error handling for invalid PAT token * Silence jq errors, dont fail, slurp curl output * Update error message to be more informative --- ubuntu/14.04/start.sh | 7 +++++-- ubuntu/16.04/start.sh | 7 +++++-- ubuntu/start.sh | 7 +++++-- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/ubuntu/14.04/start.sh b/ubuntu/14.04/start.sh index 7aa9ccb..b342ef6 100644 --- a/ubuntu/14.04/start.sh +++ b/ubuntu/14.04/start.sh @@ -54,13 +54,16 @@ trap 'cleanup; exit 130' INT trap 'cleanup; exit 143' TERM echo Determining matching VSTS agent... +set +e VSTS_AGENT_URL=$(curl -LsS \ -u user:$(cat "$VSTS_TOKEN_FILE") \ -H 'Accept:application/json;api-version=3.0-preview' \ "https://$VSTS_ACCOUNT.visualstudio.com/_apis/distributedtask/packages/agent?platform=linux-x64" \ - | jq -r '.value | map([.version.major,.version.minor,.version.patch,.downloadUrl]) | sort | .[length-1] | .[3]') + | jq -rRs '.value | map([.version.major,.version.minor,.version.patch,.downloadUrl]) | sort | .[length-1] | .[3]' 2>/dev/null) +set -e + if [ -z "$VSTS_AGENT_URL" -o "$VSTS_AGENT_URL" == "null" ]; then - echo 1>&2 error: could not determine a matching VSTS agent + echo 1>&2 error: could not determine a matching VSTS agent - check that account \'$VSTS_ACCOUNT\' is correct and the token is valid for that account exit 1 fi diff --git a/ubuntu/16.04/start.sh b/ubuntu/16.04/start.sh index 7aa9ccb..b342ef6 100644 --- a/ubuntu/16.04/start.sh +++ b/ubuntu/16.04/start.sh @@ -54,13 +54,16 @@ trap 'cleanup; exit 130' INT trap 'cleanup; exit 143' TERM echo Determining matching VSTS agent... +set +e VSTS_AGENT_URL=$(curl -LsS \ -u user:$(cat "$VSTS_TOKEN_FILE") \ -H 'Accept:application/json;api-version=3.0-preview' \ "https://$VSTS_ACCOUNT.visualstudio.com/_apis/distributedtask/packages/agent?platform=linux-x64" \ - | jq -r '.value | map([.version.major,.version.minor,.version.patch,.downloadUrl]) | sort | .[length-1] | .[3]') + | jq -rRs '.value | map([.version.major,.version.minor,.version.patch,.downloadUrl]) | sort | .[length-1] | .[3]' 2>/dev/null) +set -e + if [ -z "$VSTS_AGENT_URL" -o "$VSTS_AGENT_URL" == "null" ]; then - echo 1>&2 error: could not determine a matching VSTS agent + echo 1>&2 error: could not determine a matching VSTS agent - check that account \'$VSTS_ACCOUNT\' is correct and the token is valid for that account exit 1 fi diff --git a/ubuntu/start.sh b/ubuntu/start.sh index 7aa9ccb..b342ef6 100644 --- a/ubuntu/start.sh +++ b/ubuntu/start.sh @@ -54,13 +54,16 @@ trap 'cleanup; exit 130' INT trap 'cleanup; exit 143' TERM echo Determining matching VSTS agent... +set +e VSTS_AGENT_URL=$(curl -LsS \ -u user:$(cat "$VSTS_TOKEN_FILE") \ -H 'Accept:application/json;api-version=3.0-preview' \ "https://$VSTS_ACCOUNT.visualstudio.com/_apis/distributedtask/packages/agent?platform=linux-x64" \ - | jq -r '.value | map([.version.major,.version.minor,.version.patch,.downloadUrl]) | sort | .[length-1] | .[3]') + | jq -rRs '.value | map([.version.major,.version.minor,.version.patch,.downloadUrl]) | sort | .[length-1] | .[3]' 2>/dev/null) +set -e + if [ -z "$VSTS_AGENT_URL" -o "$VSTS_AGENT_URL" == "null" ]; then - echo 1>&2 error: could not determine a matching VSTS agent + echo 1>&2 error: could not determine a matching VSTS agent - check that account \'$VSTS_ACCOUNT\' is correct and the token is valid for that account exit 1 fi