LoginSignup
9
9

More than 3 years have passed since last update.

【令和元年版】BitBucket PipelinesでHerokuに自動デプロイ試してみた!

Last updated at Posted at 2019-05-14

概要

BitBucket
https://bitbucket.org/

無料かつ無制限のプライベートリポジトリ

Heroku
https://jp.heroku.com/

Heroku はアプリの構築、提供、監視、スケールに役立つクラウドプラットフォーム

どちらも便利でよく使います!

そして僕はこう考えるわけです。

「BitBucketにPushしたらそのままHerokuに反映されないかなぁ・・・」

いちいちHerokuにデプロイしてー、BitBucketにPushしてー、だと二重管理にもなりますし
なによりもめんどくさい!

↓こんな感じにしたい
summary.png

こんな方に読んでほしい

  • WebアプリやWebサイトの開発をしている方
  • BitBucketのリポジトリを持っている方
  • Herokuのアカウントを持っている方
  • デプロイ時にめんどくさいのをどうにかしたい方

参考

下記の記事を参考にさせて頂きました!
BitBucketのPipelineの設定方法が若干変わっているようなので、補足になればと思います!
https://qiita.com/ucc_black/items/01a36ad015be4dc7a864

手順

HerokuのAPI KEYを作成

Heroku CLIでAPI KEYつくってね~と書いてあります。
https://devcenter.heroku.com/articles/authentication
https://help.heroku.com/PBGP6IDE/how-should-i-generate-an-api-key-that-allows-me-to-use-the-heroku-platform-api

BitBucketでのPipeline設定

Pipelineを有効化

Pipelineを作成したいリポジトリに入って、設定 > PIPELINE > Settings > 「Enable Pipelines」にチェック

2019-05-14_22h07_03.png

という流れですが、ぼくは最初、 設定 > PIPELINE が表示されなくて困りました。

下図のようにサイドメニューの「PIPELINE」を一度押して中に入ったら 設定 > PIPELINE > Settings > 「Enable Pipelines」
が現れたような気がします。
2019-05-14_22h09_13.png

もし同様の状況になった場合はお試しあれ!

リポジトリ変数の設定

設定 > Pipelines > Repository variables に HEROKU_API_KEYと、HEROKU_APP_NAMEをリポジトリ変数として
登録します。

HEROKU_API_KEYには上で取ってきたAPI KEYを入力します。
2019-05-14_22h16_04.png

bitbucket-pipelines.ymlの作成

bitbucket-pipelines.yml
# This is a sample build configuration for JavaScript.
# Check our guides at https://confluence.atlassian.com/x/14UWN 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: node:latest

pipelines:
  default:
    - step:
        # set HEROKU_API_KEY and HEROKU_APP_NAME environment variables
        # set clone `depth: full' as described here: https://confluence.atlassian.com/x/Y9-5Mw
        name: Deploy to Heroku
        deployment: test   # set to test, staging or production
        # trigger: manual  # uncomment to have a manual step
        script:
          - git push https://heroku:$HEROKU_API_KEY@git.heroku.com/$HEROKU_APP_NAME.git HEAD

bitbucket-pipelines.ymlをBitBucketのリポジトリにPush

2019-05-14_23h02_23.png

最後に

意外と簡単な手順ですが、大きく手間を減らせました!!!

9
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
9