How to deploy different environments with multiple contexts

circle.yml

#1

I tryed to deploy to multiple environment with multiple context in same job_name.
Because I don’t like to write same code despite just being different environment to deploy.

I wrote like below.
But I think first -deploy will be overwrited by second -deploy section.

version: 2
jobs:
  deploy:
    docker:
      - image: google/cloud-sdk

    steps:
      - checkout
      - run:
          name: setting gcloud
          command: |
            echo $GCLOUD_SERVICE_KEY | base64 -d > ${HOME}/gcloud-service-key.json
            gcloud auth activate-service-account --key-file=${HOME}/gcloud-service-key.json
            gcloud --quiet config set project ${GOOGLE_PROJECT_ID}
            gcloud --quiet config set compute/zone ${GOOGLE_COMPUTE_ZONE}
            gcloud --quiet container clusters get-credentials ${GOOGLE_CLUSTER_NAME}

      - run:
          name: rolling update deploy
          command: |
            kubectl set image deployment/<some-deployment> app=<some-image>

workflows:
  version: 2
  build-deploy:
    jobs:
      - deploy:
          requires:
            - build
            - test
          filters:
            branches:
              only: staging
          context: staging

      - deploy:
          requires:
            - build
            - test
          filters:
            branches:
              only: master
          context: prodution

#2

Hi I also encountered the same problem, but in this way I solved it.:laughing:

jobs:
  deploy: &deploy
    ... your deploy setting ...
  deploy-staging:
    <<: *deploy-firebase
  deploy-prod:
    <<: *deploy-firebase
workflows:

workflows:
  version: 2
  build-deploy:
    jobs:
      - deploy-staging:
          requires:
            - build
            - test
          filters:
            branches:
              only: staging
          context: staging

      - deploy-prod:
          requires:
            - build
            - test
          filters:
            branches:
              only: master
          context: prodution

#3

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.