From 20935a111ef9dc4787e95bf58846130815693d0a Mon Sep 17 00:00:00 2001 From: Chris Wright Date: Fri, 28 Jun 2024 10:13:46 +0100 Subject: [PATCH] Check for deployments in progress * The `create-codebuild-deployment.sh` script fails to create a new Deployment, if there is already one in progress. * This adds in a check loop, and waits until any current Deployments are complete before attempting to create a new one. --- .../create-codedeploy-deployment.sh | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/local-exec-scripts/create-codedeploy-deployment.sh b/local-exec-scripts/create-codedeploy-deployment.sh index 844fa63..741d9c2 100755 --- a/local-exec-scripts/create-codedeploy-deployment.sh +++ b/local-exec-scripts/create-codedeploy-deployment.sh @@ -60,6 +60,25 @@ DEPLOYMENT_REVISION=$( }' ) +echo "==> Checking current Deployments for '$APPLICATION_NAME' ..." +CURRENT_DEPLOYMENT="deployment_check" +while [ -n "$CURRENT_DEPLOYMENT" ] +do + CURRENT_DEPLOYMENT=$(aws deploy list-deployments \ + --application-name "$APPLICATION_NAME" \ + --deployment-group-name "$GROUP_NAME" \ + --include-only-statuses Created InProgress Queued \ + --output text \ + --query '[deploymentId]' \ + | head -n1 + ) + if [ -n "$CURRENT_DEPLOYMENT" ] + then + echo "There is a current deployment In Progress or Queued ($CURRENT_DEPLOYMENT). Waiting before creating a new one ..." + sleep 10 + fi +done + echo "==> Creating Deployment for '$APPLICATION_NAME' ..." DEPLOYMENT_ID=$( aws deploy create-deployment \ @@ -73,7 +92,7 @@ DEPLOYMENT_ID=$( echo "==> Checking deployment '$DEPLOYMENT_ID' ..." DEPLOYMENT_STATUS=$( aws deploy get-deployment \ - --deployment-id $DEPLOYMENT_ID \ + --deployment-id "$DEPLOYMENT_ID" \ --output text \ --query '[deploymentInfo.status]' ) @@ -89,7 +108,7 @@ do echo "==> Deployment status: $DEPLOYMENT_STATUS..." DEPLOYMENT_STATUS=$( aws deploy get-deployment \ - --deployment-id $DEPLOYMENT_ID \ + --deployment-id "$DEPLOYMENT_ID" \ --output text \ --query '[deploymentInfo.status]' )