i have this scenario. i would like to deploy codes based on branches and i have 2 branches the master and development. i have the following configuration:
---------------------------------------------------------------
image: python:3.5.1
pipelines:
branches:
master:
- step:
script:
- apt-get update # required to install zip
- apt-get install -y zip # required for packaging up the application
- pip install boto3==1.3.0 # required for codedeploy_deploy.py
- zip -r /tmp/artifact.zip * # package up the application for deployment
- python codedeploy_deploy.py "DEPLOYMENT_GROUP_NAME = 'stable',APPLICATION_NAME = 'production'"
development:
- step:
script:
- apt-get install -y zip # required for packaging up the application
- pip install boto3==1.3.0 # required for codedeploy_deploy.py
- zip -r /tmp/artifact.zip * # package up the application for deployment
- python codedeploy_deploy.py "DEPLOYMENT_GROUP_NAME = 'testing',APPLICATION_NAME = 'development'"
--------------------------------------------------------------------------
i use python to do the deployment through codedeploy and s3 on aws servers and i have two deployment groups with autoscale for production and development
so the only diffrent thing is where the deployment will happen on which group and i feeded the variables to the python script. so my question is there any better way to do this using the enviroment variables on pipelines?
Hello @nadeem alherbawi,
There's no specific support for custom per-branch variables in Pipelines AFAIK, but you can easily define them in the script by using provided default variables. Combining that with YAML block reuse mechanism you can get an equivalent to your script looking something like this:
pipelines:
branches:
development:
- step: &build
script:
- apt-get update # required to install zip
- apt-get install -y zip # required for packaging up the application
- pip install boto3==1.3.0 # required for codedeploy_deploy.py
- zip -r /tmp/artifact.zip * # package up the application for deployment
- >
if [ $BITBUCKET_BRANCH = "development" ]; then
DG="testing";
AN="kenz-development";
elif [ $BITBUCKET_BRANCH = "master" ]; then
DG="stable";
AN="kenz-production";
fi
- python codedeploy_deploy.py "DEPLOYMENT_GROUP_NAME = '"$DG"',APPLICATION_NAME = '"$AN"'"
master:
- step: *build
This script worked for me producing correct argument in the last step, the only difference was that I simply echoed it rather than calling python.
Hope this helps. Let me know if you have any questions.
Cheers,
Daniil
thank you I like your solution :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.