Gitlab master pushed to heroku master branch

Hello,
I would like to automate git push heroku master when i do a git push gitlab master.
can gitlab ci or whatever do that push for me ?
Thanks

1 Like

Below a .gitlab-ci.yml script that do what you want (run on gitlab.com CI)

image: node:6.4

stages:
  - test
  - deploy

before_script:
  - apt-get update -qy
  - npm install

unit_tests:
  stage: test
  script:
    - npm run test
  cache:
    paths:
    - node_modules/
  only:
    - master
    
staging:
  stage: deploy
  script:
    - echo "deb http://toolbelt.heroku.com/ubuntu ./" > /etc/apt/sources.list.d/heroku.list
    - wget -O- https://toolbelt.heroku.com/apt/release.key | apt-key add -
    - apt-get update
    - apt-get install -y heroku-toolbelt
    - export HEROKU_API_KEY=[YOUR API KEY]
    - heroku login
    - heroku git:remote -a your-app-name
    - git push heroku master
  only:
    - master

Thank your for your sample file,
It seems that the HEROKU_API_KEY is detected but not used; I get this output:
heroku-cli: Installing CLI… 23.0MB/23.46MB
heroku-cli: Installing CLI… 23.33MB/23.46MB
heroku-cli: Installing CLI… 23.46MB/23.46MB
▸ HEROKU_API_KEY is set
Enter your Heroku credentials.
Email:
ERROR: Build failed: exit code 1

any idea ?

@ctonextio try using secure variables. Do not set the api key in .gitlab-ci.yml. See http://docs.gitlab.com/ce/ci/variables/README.html

thanks Axil,
I set the secure variable and removed from the xml file but nothing changed, here is the output:
▸ HEROKU_API_KEY is set
Email:
Enter your Heroku credentials.
ERROR: Build failed: exit code 1

here is my xml file content:

image: debian:jessie

stages:

  • deploy

before_script:

  • apt-get update -qy

staging:
stage: deploy
script:
- apt-get install -y wget ruby sudo
- wget -O- https://toolbelt.heroku.com/install-ubuntu.sh | sh
- heroku login
- heroku git:remote -a nextio-services
- git push heroku master
only:
- master

OK you can’t avoid email prompt with $heroku login
Anyway this script works (with HEROKU_API_KEY as secret variable) :

tages:
  - test
  - deploy

before_script:
  - apt-get update -qy

unit_tests:
  image: node:6.4
  stage: test
  script:
    - npm install
    - npm run test
  cache:
    paths:
    - node_modules/
  only:
    - master

staging:
  image: ruby:2.3
  stage: deploy
  script:
    - gem install dpl
    - dpl --provider=heroku --app=your-app-name --api-key=$HEROKU_API_KEY --strategy=git
  only:
    - master

Works great ! thanks!!
FYI I found a solution to the problem we had with private variables.
Once defined, you don’t need to call heroku login command.
Good to know

I don’t know why the dpl cannot find the --api-key