I have a Curl post request defined in a shell script as part of a task in my default job in a Bamboo plan.
The Curl request performs a deployment on one of my QA environments. It takes about 2 hours for finish the deployment as its a full stack deployment.
Once the deployment is done, to check the status of the deployment, I wish to send one more curl request whose response has a status field which says if its a successful deployment or not.
Here is the sample response from the request:
{
"_id" : "xxx",
"templateId" : "xxx",
"templateName" : "all full reinstall",
"epoch" : "2021-11-12T10:22:14.268Z",
"userEmail" : "[email protected]",
"playbook" : "all_full_reinstall.yml",
"repoId" : "xxx",
"repoName" : "tower-in-house",
"inventoryId" : "xxx",
"inventoryName" : "xxx",
"status" : "failed"
}
I have other stages that trigger some regression tests but these should trigger only if the status is success and not failed.
The challenge is the curl request gives a response of 200. But within the response I wish to read the field of 'status' to decide if the stage is successful or not.
I looked at Can Bamboo interpret an HTTP 400 Bad request as a failure but this talks about returning non 2xx codes. In my case it returns a 200 but one of the json response fields contains the error message that I need to look to decide if its a failure or success.
Is there a way I can proceed? Any help will be greatly appreciated.
CodePudding user response:
I think you can craft shell script which will analyse response JSON with some library like jq and then call exit 0 or exit 1 depending on status field value. In case of exit 1 Bamboo will mark task and job as failed
CodePudding user response:
I followed Oleksiy Chystoprudov's answer above and I was able to resolve this.
This is what I used
response=$(curl -s "API_Endpoint_to_check_deployment_status" | jq '.status' | tr -d '"' )
if [ "$response" = "success" ]; then
exit 0
else
exit 1
fi