Siim Mardus
09/12/2024, 7:10 AMcurl instead of CLI for making can-i-deploy checks.
Benefit of CLI is that it has the nice retry logic baked in.
Does anyone have any good examples of implementing the retry logic themselves without the use of CLI?Siim Mardus
09/12/2024, 9:28 AM#!/bin/bash
set -ex
PACT_BROKER_BASE_URL="..."
CONSUMER_APP_NAME="..."
ENVIRONMENT=${ENVIRONMENT:-prod}
MAX_RETRIES=30
RETRY_INTERVAL=10
for ((i=1; i<=MAX_RETRIES; i++)); do
response=$(curl --location "$PACT_BROKER_BASE_URL/can-i-deploy?environment=$ENVIRONMENT&pacticipant=$CONSUMER_APP_NAME&version=$CONSUMER_VERSION" \
--header 'Content-Type: application/json')
echo "$response" | jq
deployable=$(echo "$response" | jq -r '.summary.deployable')
if [[ "$deployable" == "true" ]]; then
echo "Deployment is allowed, see above for details."
exit 0
else
echo "Deployment is not allowed, see above for details."
fi
if [[ $i -lt $MAX_RETRIES ]]; then
echo "Retrying in $RETRY_INTERVAL seconds... ($i/$MAX_RETRIES)"
sleep $RETRY_INTERVAL
fi
done
echo "Max retries reached. Deployment is not allowed."
exit 1