【问题标题】:circleci: How to run a job with multiple contexts for each environmentscircleci:如何为每个环境运行具有多个上下文的作业
【发布时间】:2018-04-19 03:45:17
【问题描述】:

我正在使用 circleCI 部署生产或临时环境。 我想为每个环境对应的每个分支使用相同的作业,因为我不喜欢为每个环境编写相同的代码。

我想像下面这样写。

version: 2
jobs:
  deploy:
    docker:
      - image: google/cloud-sdk
    steps:
      - checkout
      - run: <deploying commands>

workflows:
  version: 2
  deploy:
    jobs:
      - deploy:
          filters:
            branches:
              only:
                - master
          context: production

      - deploy:
          filters:
            branches:
              only:
                - develop
          context: staging

【问题讨论】:

    标签: continuous-integration circleci-2.0


    【解决方案1】:

    有一个更好的选择不要创建多个工作流,这可能会导致复杂性,特别是在您的工作流运行多个作业的情况下,其中一些仅针对特定分支触发,而另一些则不会。

    YAML 是一种数据序列化语言,因此您仍然可以使用它的功能来简化声明。

    根据你的例子,我们可能有这样的事情:

    version: 2
    jobs:
      deploy: &deploy
        docker:
          - image: google/cloud-sdk
        steps:
          - checkout
          - run: <deploying commands>
      deploy-production:
        <<: *deploy
      deploy-staging:
        <<: *deploy
    
    workflows:
      version: 2
      deploy-production:
        jobs:
          - deploy-production:
              filters:
                branches:
                  only:
                    - master
              context: production
          - deploy-staging:
              filters:
                branches:
                  only:
                    - develop
              context: staging
    

    【讨论】:

      【解决方案2】:

      我使用多个工作流程解决了这个问题。

      version: 2
      jobs:
        deploy:
          docker:
            - image: google/cloud-sdk
          steps:
            - checkout
            - run: <deploying commands>
      
      workflows:
        version: 2
        deploy-production:
          jobs:
            - deploy:
                filters:
                  branches:
                    only:
                      - master
                context: production
      
        deploy-staging:
          jobs:
            - deploy:
                filters:
                  branches:
                    only:
                      - develop
                context: staging
      

      【讨论】:

        【解决方案3】:

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2019-10-16
          • 1970-01-01
          • 2020-05-02
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多