diff --git a/shellscripts/api-imlciserver.sh b/shellscripts/api-imlciserver.sh index f2e9b31f0cb0db2aeb014fb838fe3d550e781462..b61fe3f5c08b3aebb41a9e0b3d8726dc78d43ebb 100644 --- a/shellscripts/api-imlciserver.sh +++ b/shellscripts/api-imlciserver.sh @@ -4,7 +4,8 @@ # API CLIENT :: API REQUEST TO IML CI SERVER # # ---------------------------------------------------------------------- -# 2020-07-23 first lines <axel.hahn@iml.unibe.ch> +# 2020-07-23 v1.0 <axel.hahn@iml.unibe.ch> first lines +# 2020-07-29 v1.1 <axel.hahn@iml.unibe.ch> check "/" in branch; check http status 200 # ====================================================================== # ---------------------------------------------------------------------- @@ -54,6 +55,8 @@ function makeRequest(){ local apiRequest=$2 local secret=$3 + local outfile=$( mktemp ) + echo $line echo $apiMethod ${apiHost}${apiRequest} echo $line @@ -81,12 +84,22 @@ ${apiTS} -H "Date: ${apiTS}" \ -H "Authorization: demo-bash-client:${myHash}" \ -X $apiMethod \ - ${IMLCI_URL}${apiRequest} + ${IMLCI_URL}${apiRequest} | tee -a $outfile else curl -i \ -H "Accept: application/json" -H "Content-Type: application/json" \ -X $apiMethod \ - ${IMLCI_URL}${apiRequest} + ${IMLCI_URL}${apiRequest} | tee -a $outfile + fi + + grep "^HTTP\/" $outfile | head -1 | grep " 200 " >/dev/null + local rccurl=$? + + rm -f $outfile + if [ $rccurl -ne 0 ]; then + echo + echo "ERROR: API request failed. CURL request did not get respond status code 200." + exit 4 fi } @@ -123,7 +136,7 @@ case ${option} in ;; *) echo ERROR: invalid option [${option}] - exit 1 + exit 2 esac done @@ -133,6 +146,9 @@ echo "IMLCI_PROJECT = $IMLCI_PROJECT" echo "IMLCI_API_SECRET = $IMLCI_API_SECRET" echo +echo $branch | grep '/.*/.*' >/dev/null && ( echo "WARNING: Do NOT use a branch containing a slash [/] in the name"; echo ) + + echo ACTION: $apiAction case $apiAction in @@ -153,7 +169,7 @@ case $apiAction in ;; *) echo "ERROR: unknown action [$apiAction]" - exit 2 + exit 3 esac rc=$? @@ -162,4 +178,4 @@ echo $line date echo rc=$rc -exit $rc \ No newline at end of file +exit $rc