【问题标题】:Bitbucket pipelines- different branches on different instancesBitbucket 管道 - 不同实例上的不同分支
【发布时间】:2019-05-30 20:24:20
【问题描述】:

我的应用程序有一个流程,我有一个名为 Staging 的实例,另一个是 QA,然后有一个 Production 实例。我们从 Staging 创建分支并在验证后将它们合并到 staging 中,然后合并到 QA 中,然后在完全验证后合并到 master 中。 我是管道新手,我想实现以下流程

  • 如果推送了某个分支,则应仅在 Staging EC2 实例上进行部署,并且应切换该分支
  • 如果某个分支合并到 staging 中,则部署应该只在 Staging 上进行
  • 如果随后将暂存合并到 QA 中,则应仅在 QA 上进行部署
  • 如果某些东西被合并到 master 中,部署应该只在生产上进行

我正在将 Bitbucket 与 AWS CodeDeploy 服务一起使用,并且存储库托管在 Bitbucket 上 目前我能够在 1 个实例上部署主分支。我怎样才能做到这一点? 我的 appspec.yml 如下

image: php:7.2.13

pipelines:
  branches:
    master:
      - step:
          caches:
            - composer
          script:
            - sh bitbucket-pipelines-common.sh
            - vendor/bin/phpunit
            - sh bitbucket-pipelines-codedeploy.sh
    develop:
      - step:
          caches:
            - composer
          script:
            - sh bitbucket-pipelines-common.sh
            - vendor/bin/phpunit
  custom:
    just-test-without-cache:
      - step:
          script:
            - sh bitbucket-pipelines-common.sh
            - vendor/bin/phpunit

【问题讨论】:

    标签: git amazon-ec2 aws-code-deploy bitbucket-pipelines


    【解决方案1】:

    如果代码部署脚本从环境中提取 AWS 变量,您可以创建一个 bash 脚本以在根据分支设置环境变量的步骤之前运行,即

    #!/bin/bash
    
    if [ "$BITBUCKET_BRANCH" = "master" ]
    then
        export APPLICATION_NAME="..."
        export DEPLOYMENT_CONFIG="..."
        export DEPLOYMENT_GROUP_NAME="Development"
        export S3_BUCKET=""..."
    elif [ "$BITBUCKET_BRANCH" = "staging" ]
    then
        export APPLICATION_NAME="..."
        export DEPLOYMENT_CONFIG="..."
        export DEPLOYMENT_GROUP_NAME="Staging"
        export S3_BUCKET=""..."
    elif [ "$BITBUCKET_BRANCH" = "production" ]
    then
        export APPLICATION_NAME="..."
        export DEPLOYMENT_CONFIG="..."
        export DEPLOYMENT_GROUP_NAME="Production"
        export S3_BUCKET=""..."
    fi
    

    【讨论】:

      【解决方案2】:

      我相信您可以使用Deployments 做到这一点

      所以你会有类似的东西:

      image: php:7.2.13
      
      pipelines:
        branches:
          master:
            - step:
                deployment: production
                caches:
                  - composer
                script:
                  - sh bitbucket-pipelines-common.sh
                  - vendor/bin/phpunit
                  - sh bitbucket-pipelines-codedeploy.sh
          develop:
            - step:
                deployment: development
                 caches:
                  - composer
                script:
                  - sh bitbucket-pipelines-common.sh
                  - vendor/bin/phpunit
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-08-09
        • 2021-04-11
        • 1970-01-01
        • 2018-11-20
        • 2018-08-16
        • 2017-11-02
        • 2016-02-08
        • 1970-01-01
        相关资源
        最近更新 更多