Skip to content

Instantly share code, notes, and snippets.

@hgomez-sonarsource
Created September 30, 2015 12:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hgomez-sonarsource/efb5d2c863e81de40272 to your computer and use it in GitHub Desktop.
Save hgomez-sonarsource/efb5d2c863e81de40272 to your computer and use it in GitHub Desktop.
sample bash script using curl and ansi color code to be used with Jenkins Ansi Color Plugin
#!/bin/sh
REST_URLS=$(echo $REST_URL_LIST | tr " " "\n")
if [ "$VERBOSE_CURL" = "true" ]; then
CURL_OPTS="-v"
fi
for REST_URL in $REST_URLS
do
echo -e "\033[34mRest Call : $REST_URL\033[0m"
if [[ "$REST_URL" =~ ^#.* ]]; then
echo -e "\033[35mSkipping $REST_URL\033[0m"
else
REQ_TS=`date +%Y%m%d%H%M%S`
CURL_RET=`curl -m $REQUEST_TIMEOUT -u $SYS_USER:$SYS_PASSWORD $CURL_OPTS -o REQ-$REQ_TS -s -w "%{http_code} %{time_total}" -X GET "$SYS_URL${REST_URL}"`
HTTP_CODE=`echo $CURL_RET | awk '{print $1}'`
REQ_TIME=`echo $CURL_RET | awk '{print $2}'`
echo -e "\033[32mHTTP: $HTTP_CODE TIME: $REQ_TIME\033[0m"
HTTP_CODE=`echo $CURL_RET | awk '{print $1}'`
if [ "$HTTP_CODE" != "200" ]; then
echo -e "\033[31mRequest Failed\033[0m"
exit -1
fi
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment