How to deploy to Heroku directly from my Gitlab repository

Toanalien picture Toanalien · May 5, 2016 · Viewed 45k times · Source

In my team, we use Gitlab as a remote repository, so we are looking for a solution to auto deploy our apps to Heroku. We found Codeship for auto deploying apps to Heroku from Github.

Any tips? Tricks?

Answer

Zsolt picture Zsolt · Mar 17, 2017

If you are not prepared to use Ruby/dpl you can deploy to Heroku as follows:

Look up your Heroku API key (Account settings -> API Key on the Heroku web console) and make it available as a Gitlab secret variable e.g. HEROKU_API_KEY (Please note the values is not the same as what heroku auth:token returns...)

Then add two script lines in your .gitlab-ci.yml config file at the relevant job:

git remote add heroku https://heroku:[email protected]/<name of your heroku app>.git

git push -f heroku HEAD:master

You can see detailed explanation at http://blog.thecodewhisperer.com/permalink/deploying-jekyll-to-heroku-using-gitlab-ci