Is it possible to separate environments in circleci between Heruku accounts?

82 Views Asked by At

My main idea here is to have two separated environments - one for production and one for staging.

For that purpose, I created two repos on Heroku (I wasn't sure it was possible to make it with one repo)


version: 2.1
jobs:
  heroku/deploy-via-git:
    docker:
      - image: circleci/node:10.16.3
    steps:
      - checkout
      - run:
          name: build-dev-step
          command: echo $HEROKU_APP_NAME "This is Heroku env variable"
  setting_development_variables:
    docker:
      - image: circleci/node:10.16.3
    environment:
      HEROKU_APP_NAME: ****
    steps:
      - checkout
      - run:
          name: setting-variables-command
          command: echo "Heroku env variables are set"
  setting_production_variables:
    docker:
      - image: circleci/node:10.16.3
    environment:
      HEROKU_APP_NAME: ***2***
      NODE_ENV: production
    steps:
      - checkout
      - run:
          name: setting-variables-command
          command: echo "Heroku env variables are set"

orbs:
  heroku: circleci/[email protected]
workflows:
  production:
    jobs:
      - setting_production_variables:
          filters:
            branches:
              only:
                - main
      - heroku/deploy-via-git:
          requires:
            - setting_production_variables
          filters:
            branches:
              only:
                - main
  development:
    jobs:
      - setting_development_variables: 
          filters:
            branches:
              only:
                - staging
      - heroku/deploy-via-git:
          requires:
            - setting_development_variables
          filters:
            branches:
              only:
                - staging



Here you can see the way of how I am trying to make it work for me but it seems I cannot set any env there, neither HEROKU_APP_NAME nor NODE_ENV.

For production when I set env variable in project settings, it works fine for me. But When I try to set it here in the config file it doesn't want to work.

What am I doing wrong here that it doesn't want to set env variables for me? Or maybe there is a better way to separate modes between Heroku and CircleCI?

EDIT:

As I understand NODE_ENV variable I should set on a side of Heroku via CircleCI command, right? Not the way I am setting it here

1

There are 1 best solutions below

0
On

if anyone face the same situation, that's how I solved it

version: 2.1
orbs:
  heroku: circleci/[email protected]
workflows:
  production:
    jobs:
      - heroku/deploy-via-git:
          filters:
            branches:
              only:
                - main
          app-name: {{here goes your app name for production}}
  development:
    jobs:
      - heroku/deploy-via-git:
          filters:
            branches:
              only:
                - staging
          app-name: {{here goes your app name for development}}