Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

can i use the specific enviroment variables such as staging per branches?

nadeem alherbawi
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 27, 2019

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?

 

1 answer

1 accepted

1 vote
Answer accepted
Daniil Penkin
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
July 27, 2019

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

nadeem alherbawi
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 27, 2019

thank you I like your solution :)

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events