Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specify the git branch code to be deployed in Elastic Beanstalk environment

Is there any way to specify which git branch code to be deployed to an Elastic Beanstalk environment?

Assume, I have two git branches named test and stage and I have an Elastic Beanstalk environment named test-env.

Now, I set the branch defaults in config.yml as below:

branch-defaults: 
  test:
    environment: test-env
    group_suffix: null
global:
  application_name: test
  default_ec2_keyname: abcde
  default_platform: Ruby 2.2 (Puma)
  default_region: us-west-2
  profile: eb-cli
  sc: git

Now, what I need is if I deploy from stage branch with eb deploy test-env it should automatically deploy the code from test branch or it should throw an error..

Is there any way to do it. If no please suggest me some other way to do it..

Thanks..

like image 917
Gokul Avatar asked Jul 07 '16 10:07

Gokul


People also ask

How do you deploy codes in Elastic Beanstalk?

Open the Elastic Beanstalk console , and in the Regions list, select your AWS Region. In the navigation pane, choose Environments, and then choose the name of your environment from the list. If you have many environments, use the search bar to filter the environment list. Choose Upload and deploy.

How do I set environment variables in Elastic Beanstalk?

Elastic Beanstalk lets you enter the environment variables for each environment using the management panel. On AWS, open Elastic Beanstalk. Go to your Application > Environment > Configuration > Software Configuration . Under Environment Properties you will find a list of properties you can configure.

What are Elastic Beanstalk environments?

An AWS Elastic Beanstalk environment is a collection of AWS resources running an application version. You can deploy multiple environments when you need to run multiple versions of an application. For example, you might have development, integration, and production environments.


1 Answers

This isn't something that the EB CLI supports; it will always run a deployment from the current branch. However, it's certainly something you can script (I'm assuming you're running under bash, it wouldn't be too hard to port to Windows command shell using the for command to extract the current branch name):

deployTest.sh:
#!bin/bash
# Grab the current branch name
current=`git rev-parse --abbrev-ref HEAD`
# Just in case we have any in-flight work, stash it
git stash
# Switch to 'test' branch
git checkout test
# Deploy to  test-env
eb deploy test-env
# Switch back to whatever branchwe were on
git checkout $current
# Restore in-flight work
git stash pop
like image 181
Andy Hopper Avatar answered Oct 20 '22 09:10

Andy Hopper