Deploy Go code to Heroku with GitLab CI


I’ve created a very minimalistc repository to show, how to deploy Go code to Heroku using GitLab CI.

Automatically triggered on push/merge:


  1. Create a new Heroku Pipeline.

    New Pipeline

  2. Set up as many Heroku apps in this pipeline as you need (e.g. staging and production).


  3. git clone this repository or copy whatever you need.

  4. Get your Heroku API key found in your account.

    API Key

  5. Set the key as the variable HEROKU_API_KEY in your GitLab CI / CD Settings.

    CI/CD Variables

  6. Modify .gitlab-ci.yml and change the existing app name (-app=gitlab-heroku-deploy-*) to your newly created apps.


  • Heroku uses the $PORT environment variable (see main.go)
  • In this setup, Heroku knows what to deploy based on the modified Gopkg.toml (see buildpack for alternatives)

    root-package = ""

Further Reading

GitLab  CI  CD  Go  Heroku