ruby - 如何在 Travis Ruby on Rails 中输入 heroku 凭据

标签 ruby git ruby-on-rails-4 heroku travis-ci

我正在使用 Ruby on Rails 网站,我已经用它实现了 Travis CI 并推送到 GitHub,以便在推送到 Heroku 之前测试我的构建。

当 Travis 解析我的 github 源代码时,我收到一条错误,要求我输入我的 Heroku 凭证,然后 Travis 才能推送到 Heroku。

我想做什么

How do I pass in my heroku credentials to Travis as requested without the >risk of putting it on version control?

这是 Travis 上的构建:https://travis-ci.org/AfolabiOlaoluwa/LawVille/jobs/166099588

.travis.yml

language: ruby 
rvm:
- 2.2.4
env:
  global:
  - secure: {{ I have my travis encrypted key here }}
  - secure: {{ I another travis encrypted key here }}
  - DB=sqlite
  - DB=mysql
  - DB=postgresql
  - secure: {{ I have another travis encrypted key here }}
deploy:
  provider: heroku
  api_key:
    secure: {{ I have HEROKU API KEY encrypted by travis here  }}
script:
- RAILS_ENV=test bundle exec rake db:migrate --trace
- bundle exec rake db:test:prepare
before_script:
- mysql -e 'create database strano_test'
- psql -c 'create database strano_test' -U postgres
after_success:
- gem install heroku
- yes | ruby ./config/initializers/travis_deployer.rb
- git remote add heroku <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="dcbbb5a89cb4b9aeb3b7a9f2bfb3b1" rel="noreferrer noopener nofollow">[email protected]</a>:lawville.git
- heroku keys:clear
- yes | heroku keys:add
- git push heroku master

最佳答案

上面 @andresk 的答案非常有用,但是仅加密 api-key 对我来说不起作用,正如您从我们的评论/通信中看到的那样。

对我有用的是,从终端内应用程序的根目录运行 setup heroku --org --force ,然后按照提示获取具有正确部署脚本的 Travis 文件。

注意:--force命令是强制在已经存在的.travis.yml文件上写入脚本。

响应提示后,我的部署脚本变为:

deploy:
  provider: heroku
  api_key:
    secure: encrypted_key_was_written_here
  app: lawville # being app name on heroku which am deploying to.
  on:
    repo: AfolabiOlaoluwa/LawVille # GitHub Repo

这对我有用。

关于ruby - 如何在 Travis Ruby on Rails 中输入 heroku 凭据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39937430/

相关文章:

mysql - 数据库中删除了尖括号 (<>) 之间的字符?

eclipse - 我怎样才能在 eGit 中做相当于 git rebase -i HEAD~2 的操作?

git - 使 git diff 不打印到终端

ruby-on-rails - 如何修改 to_json 方法并向其添加动态属性 - Rails 4

html - Rails 4 中 link_to 中的样式颜色,但内联样式显示不正确

sql - 使用大于时区的查询

ruby-on-rails - 用于 Ruby 的 Bootstrap 日期选择器,禁用日期

ruby - 如何包含扩展类方法并正确引用类 var 的模块

ruby - 如何将字符串切成少于 500 个字符的 block 但不在 < > 括号内切割?

git - v2.0 从零开始。我应该继续使用现有的 git repo 还是开始一个新的?