How to deploy different branches to different Heroku apps via pipelines?

matloob August 3, 2018

Hello

I have a production and a staging app (nodejs) on Heroku. I want to create a pipeline on bitbucket so that when I push code to staging it deploys staging branch to my staging app on Heroku and master to production app?

Regards

Matloob

1 answer

1 accepted

3 votes
Answer accepted
Philip Hodder
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 9, 2018

Hi,

Have a look at the following guide we have here: https://confluence.atlassian.com/bitbucket/deploy-to-heroku-872013667.html

The only thing you'll need to do different is set up the branch configurations. Which you can learn about here: https://confluence.atlassian.com/bitbucket/branch-workflows-856697482.html

image: node:6
clone:
depth: full
pipelines:
branches:
master:
- step:
name: Deploy to production
script:
- npm install
- npm test
- git push <heroku production URL>
staging:
- step:
name: Deploy to staging
script:
- npm install
- npm test
- git push <heroku staging URL>

 

Thanks,

Phil

matloob August 9, 2018

Hi Phil

Thanks for taking the time to reply. I had found this page (https://confluence.atlassian.com/bitbucket/branch-workflows-856697482.html) too. My .yml file looks like:

image: node:8.9.2
clone:
 depth: full

pipelines:
  default:
    - step:
        name: Deploy REST API to Heroku
        deployment: production
        script:
          - git push https://heroku:$HEROKU_API_KEY@git.heroku.com/$HEROKU_APP_NAME.git HEAD
  branches:
    graphql:
      - step:
          name: Deploy GraphQL to Heroku
          deployment: staging
          script:
            - git push https://heroku:$HEROKU_API_KEY@git.heroku.com/$HEROKU_APP_NAME_STAGING.git graphql:master

 

But it never pushes from the branch graphql. What's wrong with the configuration?

Regards

Matloob

Like Tobias Thiede likes this
Philip Hodder
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 9, 2018

Do you mean that the build never triggers on the 'graphql' branch, or that the git push command fails. Do you get an error message?

matloob August 9, 2018

The push goes through to Bitbucket, but the deployment does not run for graphql.

Philip Hodder
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 9, 2018

Does it instead trigger the 'default' pipeline?

matloob August 9, 2018

Nope.

Philip Hodder
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 9, 2018

Can you double check that Pipelines is enabled?

Repository Settings -> Pipelines -> Settings

Screen Shot 2018-08-10 at 2.04.12 pm.pngYou may also be out of build minutes. You can check that on the main Pipelines page:

Screen Shot 2018-08-10 at 2.07.00 pm.png

matloob August 9, 2018

Yes, it works when I push to master. 'default' is deployed.

13.1 / 50 free minutes used this period.

 

Philip Hodder
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 9, 2018

Can you double check if there's a bitbucket-pipelines.yml file on the 'graphql' branch, and what the configuration of it is?

matloob August 9, 2018

I had created the .yml file on bitbucket on master, it wasn't there on the graphql branch. I cherry-picked the commit that added the .yml and pushed graphql and it worked.

If it needs to be on each branch, it can be branch-specific. No need for 'default' on graphql and 'branches' on master, right?

Philip Hodder
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 9, 2018

I'd recommend you have the same btibucket-pipelines.yml configuration on each branch. So on *all* your branches, you can have something like:

pipelines:
branches:
master:
- step:
script:
- # deploy to prod heroku
graphql:
- step:
script:
- # deploy to staging heroku
default:
- step:
script:
- # run any other pipelines here. Maybe some tests.

If you have the yaml the same across all branches then you won't need to worry about inconsistencies or merge conflicts across your branches.

Thanks,

Phil

matloob August 9, 2018

Yes, makes sense. Thank you.

Neeraj Jadhav October 7, 2018

Coming late to this conversation and I am facing the same issue.

 

I have three branches:

master (which is to be deployed to heroku prod app)

staging (which is to be deployed to heroku staging app)

development (no deployment)

 

I have included the following yml file in master and staging:

 

image: node:6.9.4
pipelines:
default:
- step:
script: #default script to run
- echo "This default script will run when something is pushed to this branch"
branches:
master:
- step:
name: Heroku Production Deployment
caches:
- node
script: #deploy master branch to heroku prod app
- npm install
- git push https://heroku:$HEROKU_API_KEY@git.heroku.com/$HEROKU_PROD_APP.git HEAD:master
staging:
- step:
name: Heroku Staging Deployment
caches:
- node
script: #deploy staging branch to heroku staging app
- npm install
- git push https://heroku:$HEROKU_API_KEY@git.heroku.com/$HEROKU_STAGING_APP.git HEAD:staging

 

On development the .yml file only has the default value (since I do not want to deploy when anything is pushed to development branch).

 

When I make any changes in master (or anything is merged to master) the yml runs fine but only the prod app is updated.

 

When anything is merged to staging then again the master is deployed. Its like the staging branch deployment code never runs. 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events