travis自动给github repository增加了hook钩子,可以为仓库的每次更新进行编译或者自动发布。
目前免费提供服务给github公共仓库,如果仓库是私有的是不提供免费服务的。
travis-cli安装
travis-cli提供了对github person token的加密,防止发布到github repository时候,token泄露,所以使用该组件
是很有必要的
安装步骤
- 检查ruby是否安装成功
1 2
| $ ruby -v ruby 2.0.0p195 (2013-05-14 revision 40734) [x86_64-darwin12.3.0]
|
- 安装travis
1
| gem install travis -v 1.8.10 --no-rdoc --no-ri
|
- 再次确认travis-cli安装成功
Travis Deploy Github Releases
travis每次都会读取根路径下的.travis.yml配置文件
- 使用travis-cli工具生成.travis.yml
travis setup releases
会依次输入github的用户名和密码用来做token加密,还有file用来表示要上传到github releases
- 配置文件模板以及参数介绍
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| language: java os: osx
branches: only: - master
before_cache: - rm -f $HOME/.gradle/caches/modules-2/modules-2.lock - rm -fr $HOME/.gradle/caches/*/plugin-resolution/
cache: directories: - "$HOME/.gradle/caches/" - "$HOME/.gradle/wrapper/"
before_deploy: - export TRAVIS_TAG=`cat build.gradle |grep -e '^version'|cut -d " " -f2|cut -d "'" -f2` - git tag $TRAVIS_TAG - ls ${TRAVIS_BUILD_DIR}/build - ls ${TRAVIS_BUILD_DIR}/build/distributions deploy: provider: releases overwrite: true api_key: secure: ndWxLslRBYhp4DukjyAcuxvk/asgf+DbBCUktxJ45GD1+ydpb0HatLzMUhvLyB2Vs0Z34Slm6KgXyDC5ecOqfIM/SSbr0Olc....此处省略 file_glob: true skip_cleanup: true file: ${TRAVIS_BUILD_DIR}/build/distributions/* on: repo: FlyingPigQAQ/firstblood tags: false
|
小技巧
?如何为github README 添加building pass徽章
示意图

打开travis对应github仓库构建地址
地址为:https://travis-ci.org/GITHUB_USERNAME/REPOSITORY_NAME

右键页面中的building|pass的图标,选择复制图片地址,然后再README.md中添加如下显示语句即可
那么以后每次构建,都会将最终的构建结果,通过该小图标实时的表示出来。
参考文档