gitlab-CI与Heroku集成部署
gitlab-CI Runner
1.安装runner(省略)
2.注册与配置runner(省略)
添加.gitlab-ci.yml
在项目根目录下添加文件.gitlab-ci.yml
before_script:
- echo "install dpl deploy tool"
stages:
- deploy
deploy to production:
stage: deploy
environment: production
tags:
- heroku
only:
- master
script:
- dpl --provider=heroku --app=gitlabtestci --api-key=$HEROKU_API_KEY
以上为使用ssh runner,使用了本地服务器,所以在服务器安装了heroku-cli和dpl,如果使用docker或其他shared runner,可能需要在before-script处添加安装heroku或者dpl的过程 示例如下
before_script:
- echo "install heroku"
- sudo curl https://cli-assets.heroku.com/install-ubuntu.sh | sh
- echo "install dpl deploy tool"
- sudo gem install dpl
stages:
- deploy
deploy to production:
stage: deploy
environment: production
tags:
- heroku
only:
- master
script:
- dpl --provider=heroku --app=gitlabtestci --api-key=$HEROKU_API_KEY
附录:Runner相关命令
查看帮助:
gitlab-runner run --help
使用Debug模式启动
gitlab-runner --debug <command>
注册runner
gitlab-runner register
验证状态
gitlab-runner verify
启动gitlab-runner
gitlab-runner run
启动runner
gitlab-runner start
关闭runner
gitlab-runner stop
重启runner
gitlab-runner restart
查看runner状态
gitlab-runner status
配置文件目录:
/etc/gitlab-runner/config.toml on *nix systems when gitlab-runner is executed as super-user (root)
~/.gitlab-runner/config.toml on *nix systems when gitlab-runner is executed as non-root
./config.toml on other systems