指定要部署在 Elastic Beanstalk 环境中的 git 分支代码

Gok*_*l M 6 git ruby-on-rails amazon-web-services amazon-elastic-beanstalk

有什么方法可以指定要部署到 Elastic Beanstalk 环境的 git 分支代码吗?

假设,我有两个名为teststage 的git 分支,并且有一个名为test-env的 Elastic Beanstalk 环境。

现在,我将分支默认设置config.yml如下:

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
Run Code Online (Sandbox Code Playgroud)

现在,我需要的是,如果我从阶段分支部署eb deploy test-env它应该自动从测试分支部署代码或者它应该抛出错误..

有什么办法可以做到。如果没有,请建议我一些其他的方法来做到这一点..

谢谢..

And*_*per 5

这不是 EB CLI 支持的内容;它将始终从当前分支运行部署。但是,这当然是您可以编写的脚本(我假设您正在运行bash,使用for提取当前分支名称的命令移植到 Windows 命令外壳不会太难):

部署测试.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
Run Code Online (Sandbox Code Playgroud)