Created
May 16, 2017 14:53
-
-
Save jasonamyers/1ea3e00322ab293579b588298ca44c33 to your computer and use it in GitHub Desktop.
Jenkins deploy stage blue-green ecs
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
52 stage('Deploy') { | |
53 sh """#!/bin/bash -x | |
54 export PATH=\${HOME}/bin:\${PATH} | |
55 export AWS_DEFAULT_REGION=${REGION} | |
56 [[ -d \${HOME}/bin ]] || mkdir \${HOME}/bin | |
57 [[ -e \${HOME}/bin/ecs-deploy.sh ]] || ( curl --silent -L https://raw.githubusercontent.com/silinternational/ecs-deploy/develop/ecs-deploy >\${HOME}/bin/ecs-deploy.sh && chmod +x \${HOME}/bin/ecs-deploy.sh ) | |
58 | |
59 PREVIOUS_TASK_DEF_ARN=\$(aws ecs describe-services --services $ECS_SERVICE --cluster $ECS_CLUSTER | jq -r '.services[0].taskDefinition') | |
60 ecs-deploy.sh -c $ECS_CLUSTER -n $ECS_SERVICE -i ${AWS_ACCTID}.dkr.ecr.${REGION}.amazonaws.com/${ECS_SERVICE}:latest | |
61 NEW_TASK_DEF_ARN=\$(aws ecs describe-services --services $ECS_SERVICE --cluster $ECS_CLUSTER | jq -r '.services[0].taskDefinition') | |
62 if [[ \$? -eq 0 ]] && [[ -n \$PREVIOUS_TASK_DEF_ARN ]]; then | |
63 echo "Deregistering previous task definition" | |
64 aws ecs deregister-task-definition --task-definition \$PREVIOUS_TASK_DEF_ARN >/dev/null | |
65 else | |
66 if [[ \$PREVIOUS_TASK_DEF_ARN != \$NEW_TASK_DEF_ARN ]] && [[ -n \$PREVIOUS_TASK_DEF_ARN ]] && [[ -n \$NEW_TASK_DEF_ARN ]]; then | |
67 aws ecs update-service --cluster $ECS_CLUSTER --service $ECS_SERVICE --task-definition \$PREVIOUS_TASK_DEF_ARN | |
68 aws ecs deregister-task-definition --task-definition \$NEW_TASK_DEF_ARN | |
69 fi | |
70 fi | |
71 """ | |
72 } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment