travis CI 配置 - mindpin/docs GitHub Wiki
如下图,点击通过Github登录
Github授权,需要确认
需要输入密码
选择项目
给项目添加**.travis.yml**
各种语言样板,可以参考(http://docs.travis-ci.com/user/language-specific/)
添加**.travis.yml**并且push之后,可以看到任务已经开始
下图为任务完成时候的图片,可以看到任务失败
点开查看原因是,从github安装gem,超过10分钟,被干掉了
修改了一个错误的测试之后,再次push,发现结果有点不太一样了:
点击,进入,可以查看到错误日志为:
/home/travis/.rvm/gems/ruby-2.1.0/gems/mongoid-4.0.0/lib/mongoid/sessions/factory.rb:61:in `create_session': (Mongoid::Errors::NoSessionsConfig)
Problem:
translation missing: zh-CN.mongoid.errors.messages.no_sessions_config.message
Summary:
translation missing: zh-CN.mongoid.errors.messages.no_sessions_config.summary
Resolution:
translation missing: zh-CN.mongoid.errors.messages.no_sessions_config.resolution
from /home/travis/.rvm/gems/ruby-2.1.0/gems/mongoid-4.0.0/lib/mongoid/sessions/factory.rb:43:in `default'
from /home/travis/.rvm/gems/ruby-2.1.0/gems/mongoid-4.0.0/lib/mongoid/sessions.rb:37:in `default'
from /home/travis/.rvm/gems/ruby-2.1.0/gems/mongoid-4.0.0/lib/mongoid.rb:65:in `default_session'
from /home/travis/.rvm/gems/ruby-2.1.0/gems/database_cleaner-1.4.1/lib/database_cleaner/mongoid/truncation.rb:30:in `session'
from /home/travis/.rvm/gems/ruby-2.1.0/gems/database_cleaner-1.4.1/lib/database_cleaner/moped/truncation_base.rb:26:in `collections'
from /home/travis/.rvm/gems/ruby-2.1.0/gems/database_cleaner-1.4.1/lib/database_cleaner/moped/truncation_base.rb:14:in `clean'
from /home/travis/.rvm/gems/ruby-2.1.0/gems/database_cleaner-1.4.1/lib/database_cleaner/base.rb:40:in `clean_with'
from /home/travis/.rvm/gems/ruby-2.1.0/gems/database_cleaner-1.4.1/lib/database_cleaner/configuration.rb:91:in `block in clean_with'
from /home/travis/.rvm/gems/ruby-2.1.0/gems/database_cleaner-1.4.1/lib/database_cleaner/configuration.rb:91:in `each'
from /home/travis/.rvm/gems/ruby-2.1.0/gems/database_cleaner-1.4.1/lib/database_cleaner/configuration.rb:91:in `clean_with'
from /home/travis/build/mindpin/TouchIdea/spec/support/database_cleaner.rb:3:in `block (2 levels) in <top (required)>'
from /home/travis/.rvm/gems/ruby-2.1.0/gems/rspec-core-3.2.2/lib/rspec/core/example.rb:333:in `instance_exec'
from /home/travis/.rvm/gems/ruby-2.1.0/gems/rspec-core-3.2.2/lib/rspec/core/example.rb:333:in `instance_exec'
from /home/travis/.rvm/gems/ruby-2.1.0/gems/rspec-core-3.2.2/lib/rspec/core/hooks.rb:357:in `run'
from /home/travis/.rvm/gems/ruby-2.1.0/gems/rspec-core-3.2.2/lib/rspec/core/configuration.rb:1559:in `block in run_hooks_with'
from /home/travis/.rvm/gems/ruby-2.1.0/gems/rspec-core-3.2.2/lib/rspec/core/configuration.rb:1559:in `each'
from /home/travis/.rvm/gems/ruby-2.1.0/gems/rspec-core-3.2.2/lib/rspec/core/configuration.rb:1559:in `run_hooks_with'
from /home/travis/.rvm/gems/ruby-2.1.0/gems/rspec-core-3.2.2/lib/rspec/core/configuration.rb:1525:in `with_suite_hooks'
from /home/travis/.rvm/gems/ruby-2.1.0/gems/rspec-core-3.2.2/lib/rspec/core/runner.rb:109:in `block in run_specs'
from /home/travis/.rvm/gems/ruby-2.1.0/gems/rspec-core-3.2.2/lib/rspec/core/reporter.rb:62:in `report'
from /home/travis/.rvm/gems/ruby-2.1.0/gems/rspec-core-3.2.2/lib/rspec/core/runner.rb:108:in `run_specs'
from /home/travis/.rvm/gems/ruby-2.1.0/gems/rspec-core-3.2.2/lib/rspec/core/runner.rb:86:in `run'
from /home/travis/.rvm/gems/ruby-2.1.0/gems/rspec-core-3.2.2/lib/rspec/core/runner.rb:70:in `run'
from /home/travis/.rvm/gems/ruby-2.1.0/gems/rspec-core-3.2.2/lib/rspec/core/runner.rb:38:in `invoke'
from /home/travis/.rvm/gems/ruby-2.1.0/gems/rspec-core-3.2.2/exe/rspec:4:in `<main>'
/home/travis/.rvm/rubies/ruby-2.1.0/bin/ruby -I/home/travis/.rvm/gems/ruby-2.1.0/gems/rspec-core-3.2.2/lib:/home/travis/.rvm/gems/ruby-2.1.0/gems/rspec-support-3.2.2/lib /home/travis/.rvm/gems/ruby-2.1.0/gems/rspec-core-3.2.2/exe/rspec --pattern spec/\*\*\{,/\*/\*\*\}/\*_spec.rb failed
travis_time:end:1501ca0e:start=1438054016073697856,finish=1438054023608048662,duration=7534350806
[0K
[31;1mThe command "bundle exec rake" exited with 1.[0m
Done. Your build exited with 1.
原因是,没有配置好mongoid
加入指令,自动配置mongoid.yml
# file .travis.yml 添加
before_script: ./bin/ci/before_build.sh
services:
- mongodb # start mongodb
- redis-server # start redis-server
添加bin/ci/before_build.sh
#!/bin/sh
cp config/mongoid.yml.example config/mongoid.yml
修改权限
chmod 755 bin/ci/before_build.sh
commit, push
travis ci显示的还是没有变
点击进入Build History,可以看见任务并没有开始,只能继续等等
一段时间后回来查看结果,如下图所示,测试通过
点进去查看详情,最终日志如下
14.04s$ bundle exec rake
/home/travis/.rvm/rubies/ruby-2.2.0/bin/ruby -I/home/travis/.rvm/gems/ruby-2.2.0/gems/rspec-core-3.2.2/lib:/home/travis/.rvm/gems/ruby-2.2.0/gems/rspec-support-3.2.2/lib /home/travis/.rvm/gems/ruby-2.2.0/gems/rspec-core-3.2.2/exe/rspec --pattern spec/\*\*\{,/\*/\*\*\}/\*_spec.rb
.......................................................
Deprecation Warnings:
Using `should` from rspec-expectations' old `:should` syntax without explicitly enabling the syntax is deprecated. Use the new `:expect` syntax or explicitly enable `:should` with `config.expect_with(:rspec) { |c| c.syntax = :should }` instead. Called from /home/travis/build/mindpin/TouchIdea/spec/models/infocard_spec.rb:8:in `block (3 levels) in <top (required)>'.
If you need more of the backtrace for any of these deprecations to
identify where to make the necessary changes, you can configure
`config.raise_errors_for_deprecations!`, and it will turn the
deprecation warnings into errors, giving you the full backtrace.
1 deprecation warning total
Finished in 7.98 seconds (files took 2.72 seconds to load)
55 examples, 0 failures
The command "bundle exec rake" exited with 0.
Done. Your build exited with 0.
55个测试,0个失败,即全部测试通过。
附上mindpin/TouchIdea的**.travis.yml**
language: ruby
bundler_args: --without development production
before_script: ./bin/ci/before_build.sh
env:
- CI=true
rvm:
- 2.1.0
- 2.2.0
gemfile:
- Gemfile
services:
- mongodb # start mongodb
- redis-server # start redis-server
至此,travis-ci简单配置说明结束。如果还有什么高级需求,请查看英文文档(http://docs.travis-ci.com/)