Heroku にデプロイする

Bitbucket Pipelines から Heroku にアプリケーションをデプロイします。

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

前提条件

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.

ステップ 1: Heroku の API トークンとアプリ名を環境変数として追加する

Heroku リポジトリ用に、設定で 2 つの変数を定義します。

名前
HEROKU_API_KEY API token generated from Heroku. Use a secured variable so that it is masked and encrypted
HEROKU_APP_NAME Heroku のアプリ名

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.

最終更新日: 2019 年 9 月 16 日

この内容はお役に立ちましたか?

はい
いいえ
この記事についてのフィードバックを送信する
Powered by Confluence and Scroll Viewport.