Deploy same branch to multiple apps

heroku
circle.yml

#1

How do I get the same branch pushed to multiple apps?

I’ve got 3 labels in the deployment section (ci, staging, prod), all pushing a master branch (to a heroku app)

The problem is, only the first one (ci) gets executed i.e. https://monosnap.com/file/e0eKZoKl9ut5rB6dx4OKw3soqacr2y

My circle.yml looks like this

deployment:
  ci:
    branch: master
    commands:
      - "[[ ! -s \"$(git rev-parse --git-dir)/shallow\" ]] || git fetch --unshallow"
      - git push git@heroku.com:ff-api-ci.git $CIRCLE_SHA1:refs/heads/master --force 2>&1
  staging:
    branch: master
    commands:
      # Manually fetch full repo
      - "[[ ! -s \"$(git rev-parse --git-dir)/shallow\" ]] || git fetch --unshallow"
      - git push git@heroku.com:ff-api-staging.git $CIRCLE_SHA1:refs/heads/master --force 2>&1
  prod:
    branch: master
    commands:
      # Manually fetch full repo
      - "[[ ! -s \"$(git rev-parse --git-dir)/shallow\" ]] || git fetch --unshallow"
      - git push git@heroku.com:ff-api-prod.git $CIRCLE_SHA1:refs/heads/master --force 2>&1

#2

AFAICT from the documentation, multiple labels are just fine? So I’m wondering if this is a bug?


#3

I see the same thing - see this on CircleCI at the top of the build:

     There are multiple applicable deployment sections! Using 'production'.

when I have both a ‘production’ and ‘staging’ off of branch:master

We are going to have multiple ‘production’ apps from the same codebase and we will need a way to deploy to both apps. Any workaround (have one deployment kick off another?) much appreciated!


#4

have you tried deploying with version release tags, prefixed with an app-id vs trying to deploy from a branch … ?

going through the same process now, figured having multiple develop, stage, prod branches would be an inherent nightmare (to my already existing disgust of a reality…) , and that having one branch across all apps, but tagging releases for different commits per app-id to be a simpler solution, so far so good .


#5

I’ve run into this issue as well.

I would like to continue deploying my app to heroku when the master branch builds, but also start to publish a static site for the component library for this app to GitHub Pages, also limited to only the master branch.

The deployment section seems like the appropriate place to manage this, with the available multiple subsections. The only detail in the documentation that seems to suggest that my approach is not appropriate is the following:

In instances of multiple branches, the first one that matches the branch being built is the one that is run.

Since it seems like this is an intentional limitation, are there other options? I attempted to do the deploy to GitHub Pages as a post step under test, but I could not figure out how to limit it to only deploy when building the master branch.


#6

I ran into the same problem. I really don’t understand why this behaviour would be limited on purpose.


#7

+1
This is a blocker for me. @CircleCI-Employees
Should be able to have multiple deploy sections run in the same build


#8

+1

For our project we need to build artifacts on every branch but want to push some package files to gemnasium only on pushes to master. How do we accomplish this?


#9

+1 I also have one codebase running in two Heroku apps …


#10

This is also a limitation for me :confused:


#11

Hey. I figured it out.

You can have one deployment section which can include multiple deploys.

deployment:
   demo_and_countyportal:
     branch: puma-on-heroku
     commands:
       - git push git@heroku.com:gcfdemo.git $CIRCLE_SHA1:master
       - heroku run rake db:migrate --app gcfdemo
       - git push git@heroku.com:gcfcountyportal.git $CIRCLE_SHA1:master
       - heroku run rake db:migrate --app gcfcountyportal

#12