Last active
January 7, 2020 18:18
-
-
Save zodman/4826f9a41001728fbd6db79218a9be69 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# This bash script use the Bamboo REST API in order to trigger a plan tests and wait for it to finish and get a result (failed or success). | |
# It should have a timeoput and should return success or failure | |
#This triggers the plan | |
#set -x | |
EXECUTEPLAN=$(curl -H "Authorization: Bearer ${bamboo.BEARER_SECRET}" -X POST -d "stage&executeAllStages" https://bamboo.coke.com/rest/api/latest/queue/CDSGLB-CDSDEPDCL.json) | |
echo "output of plan: " | |
echo "$EXECUTEPLAN" | |
echo "" | |
#I can parse the result of that command in order to get the build number by: | |
BUILDNUMBER=$(echo $EXECUTEPLAN | jq .buildNumber) | |
echo "Build number: $BUILDNUMBER" | |
# if there is no build number exit the script | |
if [ -z "$BUILDNUMBER" ]; then | |
echo "There is no Build number - exit the script" | |
exit 1 | |
fi | |
n=0 | |
until [ $n -ge 50 ] | |
do | |
echo "send call to get status: $n time" | |
RESULT_PLAN=$(curl -H "Authorization: Bearer ${bamboo.BEARER_SECRET}" -X GET https://bamboo.coke.com/rest/api/latest/result/CDSGLB-CDSDEPDCL/$BUILDNUMBER.json) | |
echo "output of latest result:" | |
# echo $RESULT_PLAN | |
echo "" | |
lifeCycleState=$(echo "$RESULT_PLAN" | jq .lifeCycleState) | |
echo "lifeCycleState is $lifeCycleState" | |
echo $lifeCycleState | |
if [[ "$lifeCycleState" = *"Finished"* ]]; then | |
echo "checking the state" | |
# check if success | |
State=$(echo "$RESULT_PLAN" | jq .state) | |
echo "the state is x $State x" | |
if [[ "$State" = *"Successful"* ]] | |
then | |
echo "The state is succesful!!!" | |
exit 0 | |
else | |
echo "The state is not a success: it is $State " | |
exit 1 | |
fi | |
else | |
echo "lifeCycleState is NOT finished" | |
n=$[$n+1] | |
sleep 6 | |
fi | |
done | |
echo "Script didnt get succesfull status in the expected time period" | |
exit 1 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment