Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How can I override the codedeploy block of code?

Abryan Manalansang August 17, 2020

How can I override the codedeploy block of code and use a different DEPLOYMENT_GROUP? Is this possible? I have two deployment groups (staging and production deployment groups) that target one EC2 instance. 

My goal is to deploy my application to a /staging and /production directory on my EC2.

- step: &deploy
name: Deploy to Staging
deployment: Staging
#trigger: manual # Uncomment to make this a manual step
script:
- apt-get update
- apt-get install -y zip
- zip -r application1.zip .
- pipe: atlassian/aws-code-deploy:0.5.3
name: Upload to S3
variables:
AWS_DEFAULT_REGION: $AWS_DEFAULT_REGION
AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY
APPLICATION_NAME: 'CodeDeployApp'
S3_BUCKET: $S3_BUCKET
COMMAND: 'upload'
ZIP_FILE: 'application1.zip'
VERSION_LABEL: 'app-1.0.0'
- pipe: atlassian/aws-code-deploy:0.5.3
name: Deploy to EC2
variables:
AWS_DEFAULT_REGION: $AWS_DEFAULT_REGION
AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY
APPLICATION_NAME: 'CodeDeployApp'
DEPLOYMENT_GROUP: 'staging-deployment-group'
S3_BUCKET: $S3_BUCKET
COMMAND: 'deploy'
WAIT: 'true'
VERSION_LABEL: 'app-1.0.0'
IGNORE_APPLICATION_STOP_FAILURES: 'true'
FILE_EXISTS_BEHAVIOR: 'OVERWRITE'


master:
- step: *build
- step:
<<: *deploy
name: Deploy to Prod
deployment: production
trigger: manual
script:
variables:
DEPLOYMENT_GROUP: 'production-deployment-group'

1 answer

0 votes
ktomk
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 8, 2020

I'm not so sure if this is practicable feasible with YAML merge key as it is merging hashes and requires to make use of heavy aliasing so to merge the only change at the right place.

It might be easier as this is related to deployments to make DEPLOYMENT_GROUP a deployment variable (can be setup per each deployment environment):

DEPLOYMENT_GROUP: $DEPLOYMENT_GROUP 

and alias the deploy script (in difference to the whole step as you have in your example):

# ...
- step: &deploy
name: Deploy to Staging
deployment: Staging
script: &deploy-script
- apt-get update
# ...
master:

- step: *build
- step:
name: Deploy to Prod
deployment: production
trigger: manual
script: *deploy-script

See as well the suggestion by Oleksandr Kyrdan in a question of yours. 

Abryan Manalansang September 8, 2020

@ktomk - thanks for the reply!

How would the steps in my deploy-script look like? I still can't get the picture.

If I use the alias, it will be using the same deployment group, is it not?

ktomk
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 8, 2020

If I use the alias, it will be using the same deployment group, is it not?

Yes, the same deployment group, but only on the level of the YAML, let's see it again:

DEPLOYMENT_GROUP: $DEPLOYMENT_GROUP 

The deployment group will be always the same: `$DEPLOYMENT_GROUP`.

As this is a variable, one to be set per each deployment environment, this allows you to change the deployment group for each deployment environment.

You can now control the individual deployment group by setting up the deployment variables.

As far as I have understood you, this is what you're looking for, right? Did this clarify your question?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events