CodeDeploy Environment Variables On Windows

0

I am using CodeDeploy to deploy a .Net app to a Windows Server 2022 machine. I am using an AppSpec.yml file to manage the deployment steps. I have read that you can read in the CodeDeploy environment variables such as $DEPLOYMENT_GROUP_NAME in your hook scripts e.g. https://aws.amazon.com/blogs/devops/using-codedeploy-environment-variables/. The example are always in linux scripts though e.g.

    
if [ "$DEPLOYMENT_GROUP_NAME" == "Staging" ]
then

I am wanting to do this in a cmd file as when deploying to Windows you can't use .sh files. I have tried as a test echoing the results of a variable from a cmd file but it always comes out as not being set to my Deployment Group Name. Are CodeDeploy variables not available in windows deployments or am I using them wrong. What I am trying to achieve ultimately is to know which Deployment Group (Test or Prod) is being deployed to so that I can update some configuration accordingly.

asked 2 years ago902 views
1 Answer
1

Actually figured it out. For Windows when using cmd or bat files you need to use a slightly different variable syntax. It is

%DEPLOYMENT_GROUP_NAME%

instead of

$DEPLOYMENT_GROUP_NAME

The %DEPLOYMENT_GROUP_NAME% gets replaced with the correct value. In my case "Staging".

answered 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions