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.

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

Define two variables in your settings for your Heroku repository:

Name

Value

HEROKU_API_KEY

API token generated from Heroku. Use a secured variable so that it is masked and encrypted

HEROKU_APP_NAME

Heroku app name

You can define these variable at the deployment environment, repository, or workspace level.

Step 2: Configure your Pipeline to do a full clone

Heroku deployments require a full Git clone. By default, Pipelines clones your repository with a depth of 50 to shorten your build time. You can configure your Pipeline to do a full Git clone in your bitbucket-pipelines.yml file.

Step 3: 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.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 # This is a sample build configuration for Python. # Check our guides at https://confluence.atlassian.com/x/x4UWN for more examples. # Only use spaces to indent your .yml configuration. # ----- # You can specify a custom docker image from Docker Hub as your build environment. image: python:3.7.2 pipelines: default: - step: name: Test script: - cd sample-python-app - pip install -r requirements.txt - ./manage.py test - step: name: Build script: - cd sample-python-app - git archive --format=tar.gz main -o sample-app.tar.gz artifacts: - sample-python-app/sample-app.tar.gz - step: name: Deploy to production deployment: production caches: - pip script: - pipe: atlassian/heroku-deploy:0.1.1 variables: HEROKU_API_KEY: $HEROKU_API_KEY HEROKU_APP_NAME: $HEROKU_APP_NAME ZIP_FILE: sample-python-app/sample-app.tar.gz

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

Still need help?

The Atlassian Community is here for you.