Deploy to Heroku

Deploying your application to Heroku from Bitbucket Pipelines.

A full end-to-end example is available in this repository if you prefer a more hands-on experimentation with deploying to Heroku using Pipelines and Pipes

Prerequisites

In this guide we assume that you have:

  • an existing Java app that uses Maven as a build tool.
  • a free Heroku account
  • an application created in Heroku. You can learn how to create Heroku apps here.

Step 1: Add your Heroku API token and app name as an environment variables

Define two variables in your settings for your Heroku repository:

NameValue
HEROKU_API_KEYAPI token generated from Heroku. Use a secured variable so that it is masked and encrypted
HEROKU_APP_NAMEHeroku app name

You can define these variables at the deployment environment, repository, or team level. The example below is shown with a repository variable.

screenshot showing repo varibles configured

Step 2: Use a pipe to deploy to Heroku

Deploy your application to Heroku using the Heroku deploy pipe. The pipe repository contains more usage examples, which variables you can use, and support information.


Below is a sample bitbucket-pipelines.yml configuration that deploys an application to Heroku. This example also provides insights on some best practices, like having separate steps for building and deploying an application and also using Bitbucket Deployments to deploy to different environments.

pipelines:
  default:
    - step:
        name: Build and test
        image: maven:3
        caches: 
          - maven
        script:
          - mvn -B clean verify
    - step:
        name: Create artifact
        script:
          - tar czfv application.tgz pom.xml src/
        artifacts:
          - application.tgz
    - step:
        name: Deploy to production
        deployment: production
        script:
          - pipe: atlassian/heroku-deploy:0.1.1
            variables:
              HEROKU_API_KEY: $HEROKU_API_KEY
              HEROKU_APP_NAME: $HEROKU_APP_NAME
              ZIP_FILE: "application.tgz"


You can check your bitbucket-pipelines.yml file with our  online validator.

Last modified on Oct 16, 2019

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.